jQuery Content Filter Selectors

Last Updated Jul 21, 2015, 12:00:06 PM





jQuery contains() selector

jQuery contains selector selects all elements which contain the specified text in HTML.
Syntax Example

The below example underlines the names which contain Gates asHTMLtext in it

Output


Try It Now

jQuery :empty Selector

The jQuery empty selector selects all HTMLelements that have no children (including text nodes).
Syntax Example

The below example finds all elements that are empty - which doesn't have any child elements or text.

It will select all the empty table columns and add Empty text in that fileds also it changes the background to red

Output


Try It Now

jQuery has() Selector

jQuery has selector, Selects elements the HTMLelements which contain at least one element that matches the specified selector or given condition.
Syntax Example

The below example adds blue border to the div element which has a paragraph of text

In the above example HTML code, we have fourdiv elements. Among the four div elements only first and third div elements has paragraphs. So the blue border will be applied to those two div elements only

Output



Try It Now

jQuery :parent Selector

jQuery parent selector is used to select the elements which have at least one child element

Note, that the a parent element should have at least one child element

Syntax

This is the inverse of jquery empty

Example

Finds all td elements with children, including text.

Output

jQuery parent selector Try It Now

Other Advanced jQuery Selectors you might want to learn

jQuery Complete Selectors Reference
jQuery Selectors

jQuery Basic Selectors

jQuery Child Selectors

jQuery Content Filter Selectors


Sources and Credits

The content and methods in the tutorial has been referred and updated with jQuery API and The jQuery Foundation

Last Updated Jul 21, 2015, 12:00:06 PM