Reputation: 1037
I need to select all span tag elements within a div with an id list_{[0-9]}+
having the following form:
<div id="list_1234" ...>
<!-- can be nested multiple levels deep -->
...
<span class="list_span">Hello</span>
</div>
How can I do that, e.g. without using jQuery? Is that possible?
Upvotes: 0
Views: 2790
Reputation: 4888
If you're happy with css3 selectors you could do something like
div[id^="list_"]
But this will also target divs with ids like list_foo
.
Upvotes: 6
Reputation: 4050
The only thing you can do is:
list_1 span, list_2 span, list_3 span... { ... }
Is it possible to add a "class" attribute to these divs? That's the proper way to handle multiple elements with ids.
Upvotes: 0
Reputation: 630429
You can do this with pure CSS pretty easily, just give those divs a class like this:
<div id="list_1234" class="container" ...>
And CSS like this:
.container span { /* styles */ }
Upvotes: 3
Reputation: 9389
Why you do'nt use a common class ? You can add many class
class="list_1234 mydiv"
And your selector :
.mydiv span
Upvotes: 2