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
Post a Comment