jquery - Javascript else if statement not working -
i have following:
html
<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>
javascript
$('#message').click(function(){ if($("a", this).is(":contains(ok)")) { console.log("im in ok!!"); } else if($("a", this).is(":contains(cancel)")) { console.log("im in cancel!!"); } });
this works fine when hit ok button , executes expected, when hit cancel code in ok executed only. cancel code never executes! doing wrong?
this
element event bound to. it's always #message
, therefore $("a", this)
both buttons. .is
scan both buttons see if of them contain "ok"
. first 1 does, goes 1st block.
you should binding events buttons themselves, not entire div.
Comments
Post a Comment