javascript - How to clear a textarea with jquery? -


i have 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>  </div> 

i want clear textarea contents when click cancel button. have:

$('#message').on("click", "a", function(){     if($(this).is(":contains(cancel)")) {        $("#send_message")(                   function(){                   $(this).val('');                  }                 );      }      else if($(this).is(":contains(ok)"))  {                 ......     } }); 

but doesn't anything. how can fix this.

you can use this:

$('#message').on("click", "a", function () {     if ($(this).is(":contains(cancel)")) {         $("#send_message").val('');     } else if ($(this).is(":contains(ok)")) { // other code      } }); 

demo here

in code used selector $("#send_message"), cannot add function after way.the $(this) referred in "wrong placed" function "have" using id selector. used idea , corrected things on code make work.


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -