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
»

How to Optimize jQuery Code for Better Performance

jQuery is the most popular client side library, in fact almost every ...

article image
»

Using Head.js to Load All Your JavaScript

In the past few years, client side frameworks/libraries have become ...

article image
»

How to Detect Browser Using jQuery

One of the more frustrating parts of creating a new web project is ...

article image
»

Convert Images to Black and White using jQuery

Converting an image to black and white is no longer a manual event. ...

article image
»

How to Use jQuery to Set Textarea Max Length

If you have a textarea field on any of your sites, it might be a good ...

getTable
»

15 Awesome jQuery Table Plugins

Tables are the most preferred way to display data because rows and ...

article image
»

How to Dynamically Open External Links in New Window

Any web developer will probably know that using the ...

article image
»

How to Use jQuery’s .not() Method

jQuery’s .not() method is a method that allows you to return ...

article image
»

jQuery Snippets: How to Add/Remove Classes After Delay

In your projects, there can often be instances of wanting to change ...