I’ve generated some divs with .append() method.
Code looks like that:
$("#someDiv").prepend("<div id='someId' class='myClass'></div>"):
$("#someDiv").prepend("<div id='someId2' class='myClass'></div>"):
that works great, now, i want to use that divs id’s.
i’m trying to do it this way:
$(".myClass").click(function(){
alert($(this).attr('id'));
})
but, it does not work, help me please.
If the elements are dynamically generated, you probably need to delegate the event to an element that actually exists when binding the handler, something like:
And you’ll need to replace the colon on the end of you’re prepends with a semicolon to make those work.
FIDDLE