I dynamically create a new div
(with a "textbox" class and ID), and some other elements inside of it, and later on in my code I bind that div
to the click event, and display the element clicked, like so:
$('#textbox_'+i).bind('click', function(event){
alert(event.target.className);
}
This is fine, and it'll give me textbox
as one of the classes displayed.
But event.target.hasClass()
doesn't seem to work. So, when I do the following, nothing happens:
$('#textbox_'+i).bind('click', function(event){
if(event.target.hasClass('textbox')) { alert('got it!'); }
}
I tried it a few different ways and it appears to me that event.target.hasClass()
just doesn't work. Is there another way to deal with events or am I doing something wrong?