开发者_运维技巧I have a table inside a div. Each td
in the table has a class.
I want to get a td
from the div
.
I though that children function could get the td
but seems it does not.
var parentDiv = $(".divClass");
parentDiv.each(function (index) {
var childTd = $(this).children(".tdClass");
Any help!
Why do not you want to use simple query. The jQuery was designed for things like this:))
var tdArray=$(".divClass .tdClass")
If you want to traverse through all the td's. You need something like this.
$(".divClass table tbody tr td ").each(function (i,ele){
}
Only td with a particular class
$(".divClass .tdClass).each(function (i,ele){
}
Just use, the find method of jQuery:
$("#.divClass").find('td')
or $("#.divClass").children('td')
or in a normal table
$("#.divClass").find('tr').children('td').
What I'm using is appending rows in a table.
I'm using
$("#.divClass").find('tbody').append($('<tr>')
.append($('<td>')
.text("testdata")
)
.......
to get all the td you can do :
$(".divClass > td.className ").each(function (i,ele){
}
to access a specific td then,
$(".divClass > td.className ").eq(0);
this might help you
精彩评论