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
  • 34,265
  • 92
  • 284
  • 515

2 Answers2

6

it should be

if($(this).is(":contains(OK)")) {
Arun P Johny
  • 384,651
  • 66
  • 527
  • 531
1

You can use filter

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

Check Fiddle

Sushanth --
  • 55,259
  • 9
  • 66
  • 105