I have a structure of html like this:
<div id="triger1">some elements inside</div> <div id="triger2">some elements inside</div> <div id="triger3">some elements inside</div> <div id="triger4">some elements inside</div>
How do I get array of all the div's in JQuery with the triger ID in them (as you can see, they all have triger but different numbering eg. triger1, triger2 etc...)
Thanks in advance
You can use the following:
This will return all
id starting (
You can get more information about the various jQuery selectors in the jQuery docs:
you can actually use a regular expression in a selector to achieve exactly what you are looking for, as such:
(Note: this does require the regex-selector plugin)
Someone asked a similar question here.
You can read all about regular expressions here.
As others have pointed out, you can achieve the same result like this:
div elements whose
id attribute contains the string
There's more about using
*= in the jQuery documentation: Attribute Contains Selector [name*="value"]
var trigerList = $("div[id^='triger']");
©2020 All rights reserved.