Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery selector for <div> which does not contain <img>?

How do I select all <div> elements which do not contain any <img> elements using jQuery?

like image 913
jessegavin Avatar asked Apr 12 '10 19:04

jessegavin


People also ask

Which CSS selector can you not use in jQuery?

jQuery :not() Selector The :not() selector selects all elements except the specified element. This is mostly used together with another selector to select everything except the specified element in a group (like in the example above).

How do I select a specific tag in jQuery?

The jQuery #id selector uses the id attribute of an HTML tag to find the specific element. An id should be unique within a page, so you should use the #id selector when you want to find a single, unique element.

Which is the correct jQuery selector statement to select all div elements?

Which is the correct jQuery selector statement to select all <div> elements? Explanation: The statement $("div") is the correct syntax to select all <div> elements.

How will you select all the div elements on the page using jQuery?

The jQuery syntax is a little simpler, but not much more: $("div") is the jQuery equivalent to document. getElementsByTagName("div") . Here is the API documentation on jQuery's element selector: “Description: Selects all elements with the given tag name.


1 Answers

$('div:not(:has(img))')
like image 116
Tatu Ulmanen Avatar answered Oct 21 '22 21:10

Tatu Ulmanen