javascript - Getting text from all the classes on a click event -
there multiple elements each class p1,p2,p3....p14 so, when try text class clicked,i text classes! example, when the text has 80 808080080808080808080. there work-around this, else giving each id?
$('.p1,.p2,.p3,.p4,.p5,.p6,.p7,.p8,.p9,.p10,.p11,.p12,.p13,.p14').click(function(event) { if(!playerselected) { playername = this.title; // gets text classes playernumber = $('.' + this.classname + '>strong').text(); console.log(playername + " : " + playernumber); playerselected = true; } });
you need @ target element alone:
playernumber = $(this).find("strong").text(); now text target element alone.
in case:
playernumber = $('.' + this.classname + '>strong').text(); you querying elements matching classname. it's returning text elements same classname.
Comments
Post a Comment