Friday 15 February 2013

javascript - jQuery find name of clicked button by class -



javascript - jQuery find name of clicked button by class -

i have 3 tables buttons , have same name class

<table> <tr><td><span class="info">some text 1</span></td> </tr> <tr><td><button class="howdy">print out</button></td></tr> </table> <table> <tr><td><span class="info">some text 2</span></td></tr> <tr><td><button class="howdy">print out</button></td></tr> </table> <table> <tr><td><span class="info">some text 3</span></td></tr> <tr><td><button class="howdy">print out</button></td></tr> </table>

i need when click in 1 of buttons value of span illustration if click in first button value text 1 used jquery code in result give me value

$(".howdy",this).click(function(e) { cart=$(".info").text(); console.log(cart); });

try this

$('.howdy').on('click', function(){ console.log($(this).closest('table').find('.info').text()); });

you start travesring $('.howdy') button , looking closest <table> looking .info class within , getting .text()

jsfiddle

javascript jquery

No comments:

Post a Comment