Want to add a td padding with jquery

I need to find a td inside a div and add a class to all td inside that div, how can I do that with jquery?

0


a source to share


2 answers


$("#myDiv td").addClass("myClass");

      



+3


a source


JQuery selectors

are based on CSS selectors. "space" between selectors finds all children of the parent node (recursively).

In this way:

$('#myDiv td')

      



Finds #mydiv first, then gets all descendants (finds children recursively) and then checks if they are 'td', filtering out the rest.

If you only want to apply the class to the immediate children of '#mydiv':

$('#myDiv > td')

      

+2


a source







All Articles