1

I have the following:

<div class="tab-pane" id="message">
      <textarea rows="4" cols="50" id="send_message" placeholder="Enter text ...">  </textarea>
      <a href="#message" class="btn btn-large btn-info"  data-toggle="tab">OK</a>
      <a href="#message" class="btn btn-large btn-info"  data-toggle="tab">Cancel</a>

I want to bind the click method to the 'a' elements , and when one is clicked do separate things. I am trying to distingish between them using the button text but I'm getting a syntax error when I do:

$(function(){

$('#message > a').click(function(){
   if(this:contains("OK"))) {
// code to be executed if condition is true
} 
else {
// code to be executed if condition is false
}
....

How can I fix this?

user1592380
  • 30,233
  • 76
  • 247
  • 468

2 Answers2

6

it should be

if($(this).is(":contains(OK)")) {
Arun P Johny
  • 376,738
  • 64
  • 519
  • 520
1

You can use filter

if($(this).filter(':contains("OK")').length ) {

Check Fiddle

Sushanth --
  • 54,565
  • 8
  • 62
  • 98