Moving live() from jquery 1.4 to jquery 1.11 -


i have following piece of code:

    $(".watermark").live('focus', function() {         $tb = $(this);         if ($tb.val() == this.title) {             $tb.val("");             $tb.removeclass("water");         }     }).live('blur', function() {     ...     }     }).blur(); 

how can upgrade/rewrite code take advantage of latest jquery features?

here's jsfiddle http://jsfiddle.net/6ekvv/

since .live() deprecated of version 1.7 , removed in version 1.9. can use .on() instead:

$(".water").addclass('watermark'); $(".watermark").on('focus', function() {     $tb = $(this);     if ($tb.val() == this.title) {         $tb.val("");         $tb.removeclass("water");     } }).on('blur', function() {     $tb = $(this);     if ($.trim($tb.val()) == "") {         $tb.val(this.title);         $tb.addclass("water");     } }).blur(); 

Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -