X

LATEST #JQUERY NEWS

jQuery’s .children() Method


Just like in CSS, it’s possible to use jQuery to select the children of an element and apply jQuery to them. This can be done using jQuery’s .children() method. The method works pretty much like any other jQuery method — to select all of the children of an element, use the parent element as the selector and apply the .children() method to it:

$(“.main”).children();

The example above simply selects all of the children of the .main class element(s). To apply jQuery to those elements, you’ll need to do some method chaining like in the example below:

$(“.main”).children().css(“color”, “#000”);

In the example above, we’re not only selection all the children of the .main class, but we’re also adding CSS rules to them (in this case, the rule is to make all of the text black).

The .children() method does accept a filter parameter, which you can use to select specific children of a certain element. To use this feature, you’ll need to pass the element type or the element’s class or ID through the parameters of the .children() method to be sure that only children of this element type, class, or ID are selected.

$(“.main”).children(a).css(“text-decoration”, “underline”);

The example above uses the filter parameter to only select the children of the .main element(s) that are also a elements, and then applies a CSS rule to those a elements.

Recently Published

article image
»

7 Responsive jQuery Dropdown Menu Plugins

Dropdown Menu Plugins Dropdown menus are mostly used for website ...

article image
»

20 Stylish and Modern jQuery Tooltip Plugins

jQuery Tooltip Plugins Tooltips are a great option for showing extra ...

article image
»

15 Newest jQuery plugins for responsive website

Due to the proliferation of smartphones and tablets, responsive ...

article image
»

How to use Redux with jQuery

State management is one of most integral parts of any software and a ...

article image
»

Fade HTML Table Row on Hover Using jQuery

HTML tables are the ideal choice for displaying data in tabular form. ...

article image
»

Drag and Drop HTML Table Rows Using jQuery

HTML tables are the preferred UI option for displaying data. Sorting, ...

article image
»

Top 5 Best JavaScript Template Engines

Template engines help in the decoupling of HTML and JavaScript code ...

article image
»

3 jQuery/JavaScript Plugins for Push Notifications

Push notifications started from the mobile business but this ...

article image
»

Create Smooth Animation Using jQuery’s “stop()”

Making Quick Work jQuery’s animate() method is a quick way to ...