Call elements inside $(this)?

jquery

Solution

You can use `children` method:

$("tr").each(function(index) {

    // get class a text
    var text1 = $(this).children("td.a").text();

    // get class b text
    var text2 = $(this).children("td.b").text();

    // get class c text
    var text2 = $(this).children("td.c").text();

});

Problem

Possible Duplicate: How to find an element within an element Im running a loop to go through each table row. I want to access the elements inside each table row. How do I do this? Table: ``` <table> <tr> <td class="a">x</td> <td class="b">x</td> <td class="c">x</td> </tr> <tr> <td class="a">x</td> <td class="b">x</td> <td class="c">x</td> </tr> <tr> <td class="a">x</td> <td class="b">x</td> <td class="c">x</td> </tr> <tr> <td class="a">x</td> <td class="b">x</td> <td class="c">x</td> </tr> </table> ``` Code doesnt work: ``` $("tr").each(function(index) { // get class a text $(this + " td.a").text(); // get class b text $(this + " td.b").text(); // get class c text $(this + " td.c").text(); }); ```

Original source

Related problems