Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select all element with a not null id, in jQuery

I want to implement .draggable class to all elements in my document, with an existing id using jQuery 1.4.2

<div id="blabla">asdsda</div> -> OK
<div>dsds</div> -> NOT OK

Is this possible ?

i tried : $("*[id!=null]") but i does not work :s

like image 753
div1n Avatar asked Sep 10 '10 13:09

div1n


People also ask

How to select a id in jQuery?

In jQuery, the class and ID selectors are the same as in CSS. If you want to select elements with a certain class, use a dot ( . ) and the class name. If you want to select elements with a certain ID, use the hash symbol ( # ) and the ID name.

How to use not selector in jQuery?

jQuery :not() SelectorThe :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 write not contain in jQuery?

$(':not(:contains('+ userString +'))'). hide(); will hide all of the elements not containing that string.

Can we use multiple selectors in jQuery?

You can specify any number of selectors to combine into a single result. This multiple expression combinator is an efficient way to select disparate elements. The order of the DOM elements in the returned jQuery object may not be identical, as they will be in document order.


2 Answers

$('[id]')

This will grab all elements that have an 'id' attribute.

Or to get all divs with an 'id' attribute you can do:

$('div[id]')

Has Attribute Selector

like image 62
Rocket Hazmat Avatar answered Sep 21 '22 14:09

Rocket Hazmat


$("*[id]")

should work, and - for the record -

$("*:not([id])")

is the opposite.

like image 26
Tomalak Avatar answered Sep 21 '22 14:09

Tomalak