Possible Duplicate:
Select inner text (jQuery)
I have a span:
<span class="test"> target_string </span>
And the event, that is fired on click on any element of the page.
$('body').click(function(event){
if ($(event.target).attr('class') == 'test'){
alert(???);
}
}
How can I obtain target_string value?
Use $(event.target).text()
to get the text.
Possibly more efficient to delegate from the body:
$('body').on('click', '.test', function(event){
alert($(this).text())
});
Try below,
$('body').click(function(event){
var $targ = $(event.target);
if ($targ.hasClass('test')){
alert($targ.text());
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With