O'Reilly logo

jQuery and JavaScript Phrasebook by Brad Dayley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Selecting Elements Based on Content

$("p:contains('free')");   //selects <p> elements that contain "free $("div:has(span)");   //selects <div> elements that contain <span> elements $("div:empty");   //selects <div> elements with no content or children $("div:parent");   //selects <div> elements that have at least some content

Another set of useful jQuery selectors are the content filter selectors. These selectors allow you to select HTML elements based on the content inside the HTML element. Table 4.3 shows examples of using content selectors.

Image

Table 4.3 Examples of Using Content jQuery Selectors

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required