<div id='1'></div>
<div id='1_1'></div>
<div id='1_1_1'></div>
<div id='1_1_2'></div>
<div id='1_2'></div>
<div id='2'></div>
<div id='2_1'></div>
<div id='2_2'></div>
<div id='2_2_1'></div>
Given this (psuedo) set of tags, I would like to be able to get all of the “level below” tags.
e.g.
id=1 gets 1_1 and 1_2, but not 1_1_1 etc.
id=2_2 gets 2_2_1 etc
I have tried the div[id^=1] but this returns all levels below.
Note, these are NOT nested tags, so Children doesn’t work 🙁
How can I restrict to just id_?
e.g. div[id=1_1_?]
Is there a single character wildcard, or a way of restricting the length of the selector?
You could use the attribute starts-with selector you mentioned, and then filter the results:
Here’s a working example. Note that this also returns the
divwith just1as it’sid. You could prevent that by adding another condition to thereturnstatement:Finally, note that
idvalues cannot start with a number unless you’re using the HTML5 doctype.