javascript - jquery select first td of a tr in a table, then iterate through the findings and compare text with value -
having table like:
<table id="table_1"> <tr><td>1</td><td>foo</td></tr> <tr><td>2</td><td>foo</td></tr> <tr><td>3</td><td>foo</td></tr> <tr><td>4</td><td>foo</td></tr> </table> i want first td of each table row. want iterate through findings , compare text value contained in td value have.
so far, can first td of each tr using following :
var test = $("#table_1").find('td:first-child'); then number of tds : console.log(test.length); when try text of td error : console.log(test[1].text()); error:
uncaught typeerror: test[1].text not function obviously wrong. way of thinking wrong? how can fix it?
test[1] return underlying dom element , .text() jquery function getting error.
i think, need use .eq()
reduce set of matched elements 1 @ specified index.
code
test.eq(0).text() note: supplied index zero-based, , refers position of element within jquery object, not within dom tree.
or, use textcontent
test[1].textcontent
Comments
Post a Comment