Flux RSS des billets

DotMG's joblog

Work hard at whatever you do! (Ecc. 9. 10a)
jQuery: get innerText of the clicked element
Publié le 9 Oct 2012, 2:40 am dans jQuery

I'm rather bad at jQuery. I had a philosophy of avoiding technologies and funny stuffs that could alter accessibility. No java applets, no flash, and very few javascript codes. But with jQuery, portability of javascript codes is getting better, and nowadays, few people have javascript disabled on desktop ... On a mobile device, it's another story.

So, it took me more than 30 minutes to find out how to retrieve the innerText of a clicked element inside a .click(). Sometimes, the problem with javascript debugging is that almost everything is an object, and when you alert($k); to see what it is, you'll only know that it's an object. My fault is that I didn't read the documentation enough to know how to access the clicked object.

$('.myquery a').click(eventObj) {
 var clicked_object = $(this);
Les commentaires sont fermés pour ce billet.