Reputation: 6894
I'm creating a span tag dynamically and wanted to add onclick event to it.
$('<span>', {
'onclick': //call some method -> $.hello('dsfds',90),
'class' : 'rightArrow'
}).appendTo($(elm).find('div').eq(2));
How can i bind onclick in above code?
Upvotes: 0
Views: 60
Reputation: 8154
$('<span>').bind('click', function() {
//call some method -> $.hello('dsfds',90)
})
.addClass('rightArrow')
.appendTo($(elm).find('div').eq(2));
Upvotes: 1
Reputation: 150253
$('<sapn class="rightArrow"> Click of you dare</span>').click(function() {
alert('clicked!');
}).appendTo($(elm).find('div').eq(2));
Upvotes: 3