简体   繁体   中英

Jquery: Select the second td of tr element

i will select the closest tr and save it to a variable

var closestElement = $(this).closest('tr');

later in some part i need to get the 2nd td of this element and want replace the text with my own text .

How can i do it in jquery ?

尝试:

$(closestElement).find("td:eq(1)").text("your text");

Try this :

closestElement.children(':eq(1)').text('your own text');

http://api.jquery.com/eq-selector/

    var closestElement = $(this).closest('tr');

     closestElement.find("td:eq(1").text("desire text");

in single line you can do by following way.

    $(this).closest('tr').find("td:eq(1)").text("desire text");

reference eq()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM