I am using jQuery v.1.7.1 where the .live() method is apparently deprecated.
The problem I am having is that when dynamically loading html into an element using:
$('#parent').load("http://...");
If I try and add a click event afterwards it does not register the event using either of these methods:
$('#parent').click(function() ...);
or
// according to documentation this should be used instead of .live()
$('#child').on('click', function() ...);
What is the correct way to achieve this functionality? It only seems to work with .live() for me, but I shouldn't be using that method. Note that #child is a dynamically loaded element.
Thanks.
.live()
it tells you how to rewrite existing uses of.live()
to use.delegate()
or.on()
(depending on whether you're on version 1.7+ or not). Note though that if you add a handler with.click()
"afterwards" as you mention, i.e., after dynamically loading elements, it should work - the only problem is trying to assign with.click()
before dynamically loading elements. – nnnnnn