I can’t find any good documentation on this suprisingly so I’m posting it here.
What’s the raw javascript equivilent to this:
$(elem).click(function(){
alert(this.text());
});
All I can find is this <elem onlick="func()" /> which is not what I want, I want to be able to do it just with javascript not within the context of an element.
Assuming
elemis an element node (if not, you’ll need to work your selector into use ofgetElementByIdor whatever):textContentis the standards-compliant way of getting text from an element;innerTextis the IE way. (There are a few differences, but hopefully nothing that will affect you.) If you need to support old/obscure browsers that have neither you would have to do an tedious tree-walk to pick up all text (this is what jQuery’stext()does.)(I’m assuming that’s what you want from
this.text(). That wouldn’t actually work — presumably you meant$(this).text().)