Link to home
Start Free TrialLog in
Avatar of James Mor
James Mor

asked on

get all child elements using a regex pattern?

How would i get all child elements of a root element by class name using a regex pattern?

something like this

var items = $("#root_element_id").children("div:regex(class,\_[a-z0-9]{4})");
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

Yep - exactly like that. You will need to include the Regex Selector extension as it's not standard (https://gist.github.com/fny/1887398)

Then you just setup your regex to match whatever you need. Your selector will currently select all direct children of #root_element_id that have a classname starting with underscore and followed by at least 4 (case-insensitive) alphanumeric characters

<div id="root_element_id">
    <div class="_blue">MATCH</div>
    <div class="_myClass">MATCH</div>
    <div class="testClass">NO MATCH</div>
    <div class="_a123456">
        MATCH
        <div class="_blue">NO MATCH</div>
    </div>
</div>

Open in new window

This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.