JQuery selector for table cells except first/last

2019-03-10 21:34发布

问题:

is there a way to directly select all 'inner' table cells (<td> elements) of a table (i.e. all cells except the ones in the first and last row and column) using a jquery selector expression?

回答1:

You can use :not() with the :first-child and :last-child selectors, like this

$('table td:not(:first-child, :last-child)')

To exclude first/last rows as well:

$('table tr:not(:first-child, :last-child) td:not(:first-child, :last-child)')


回答2:

 $('#table_name tr td:not(:first-child)').each(function () {
                    $(this).html('<input type="text" value="' + $(this).html() + '" />');
                });

Here example how to Skip 1st td of a table(table_name) .U can write :last-child to skip last td to do some task.