Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery Select elements using wildcard (*) [duplicate]

I'm new to JQuery please help. I need to select multiple elements knowing only part of Id: eg:

<div id="element32422455">Some content</div>
<div id="element68475124">Some content</div>
<div id="element42352355">Some content</div>

Is is possible to select those elements using staff like this

$('#element*');

If you know any other good way to do it, please tell.

like image 869
Iegor Benzyk Avatar asked Mar 22 '16 19:03

Iegor Benzyk


1 Answers

You can do it by using attribute starts with selector,

var elems = $('[id^=element]');

There is no need to use wild card selector at this context, it is actually called attribute contains selector. And that will select the element though it has id like "123213element12312"

DEMO

like image 148
Rajaprabhu Aravindasamy Avatar answered Sep 27 '22 21:09

Rajaprabhu Aravindasamy