onclick event with jQuery for a dynamically created div
Posted: 28 Dec 2014, 09:10
I am using a jQuery script that adds dynamically a Div in the DOM. I am trying to ad onclick event for this div.
HTML:
After the Div is added dynamically in the DOM it looks like this
My jQuery code to register onclick to ".sm2_23ui" element:
But it doesn't work.
Does someone know how to register onclick event for a dynamically created html element?
HTML:
Code: Select all
<div class="ui23"><span>Track1</span></div>
Code: Select all
<div class="ui23">
<div class="sm2_23ui"><span class="sm2_360btn sm2-360btn-default">Button</span></div>
<span>Track1</span>
</div>
Code: Select all
$('.sm2_23ui').live(click,function(){
alert("Playing");
});
Does someone know how to register onclick event for a dynamically created html element?