During the running of my website i create new divs using jquery with class "a". I have defined a click() function for "a" class as follows:
$(document).ready(function() {
$(".a").click(function(){
$(".a").hide();
});
});
Problem is that the new divs created with the same class do not call this function when clicked. Other divs with "a" class which are there at the beginning do. What am I doing wrong?
Use the "live" method.
http://api.jquery.com/live/
This might also work.
.on() attaches events to controls that are both present and not yet present.
Try using the
.live()
function which should also apply for newly inserted DOM elements that match your selector: