- Get or set the HTML inside of a div in JavaScript:
var whatitwas = document.getElementById('whatever').innerHTML;
document.getElementById('whatever').innerHTML = whatitisnow;
- bind/live/delegate in jQuery:
$('#foo').bind('click', function() {
alert($(this).text());
});
$('#bar').live('click', function() {
alert($(this).text());
});
$("table").delegate("td", "hover", function(){
$(this).toggleClass("hover");
});- bind effects immediate entities
- live effects those that may appear later too
- I've never used delegate, but, per Justin Pope:
- delegate takes three parameters
- delegate is a marginally more performant version of live
- delegate must be declared before the thing it effects comes into memory
Note: After I wrote the above today, Steve Flitcroft told me over Twitter that I should use .on instead of .live or .delegate.
Another Note: (writing this a day after I wrote this blog posting) Mr. Flitcroft also gave me a link to: http://www.ultimatewebtips.com/why-jquery-live-is-a-bad-option-to-use/
No comments:
Post a Comment