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 Use Google Analytics with jQuery Mobile

jQuery Mobile is an HTML5 based web-page framework that’s ...

article image
»

jQuery Snippets: Using jQuery to Check All Boxes

When you’ve given your users a ton of checkbox input fields ...

article image
»

Useful jQuery Code Snippets for Working with Images

Images are an essential part of any website and sometimes working ...

article image
»

How to Use jQuery to Check if Cookies are Enabled

A cookie (not the kind with chocolate chips) is a small piece of data ...

article image
»

A Beginner’s Guide to jQuery’s Selectors

We talk a lot about event methods on this site, but not so much about ...

article image
»

Add Keyboard Shortcut to Anchor Tag Using jQuery

Making a user friendly website can be quite a challenging task. There ...

Screen Shot 2017-04-23 at 10.15.41 AM
»

How to Use jQuery to Create a Sticky Navigation on Scroll

Creating “sticky” elements is something that can often be ...

article image
»

How to Use jQuery’s Keystroke Methods

jQuery has a few built-in keystroke methods that are all triggered by ...

article image
»

How to Change iFrame Styling Using jQuery

If you’ve ever had the displeasure of working with iFrames, ...