Created
April 27, 2012 17:59
-
-
Save markmarkoh/2511352 to your computer and use it in GitHub Desktop.
$.fn.live mishap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// $.fn.live misuse | |
(function() { | |
// cache all elements that match this selector *as they exist on the page right now* | |
// let's say this is empty at this point in time | |
var $posts = $(".posts"); | |
// set up a click listener. this is totally valid with $.fn.live, | |
// any new ".posts" that get added to the DOM will automatically respond to this | |
$posts.live('click', function() { | |
//update all the HTML of all the ".posts", this selector is still *EMPTY* | |
$posts.html("this doesn't work the way you might expect"); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment