Manuel
Manuel

Reputation: 11469

How to select elements with attributes that start with something?

A lot of frameworks implement their own attributes (ng-, v-, bind-, etc.) Is there a way to select elements that have attributes starting with some string? (without looping through all elements and their properties)

Upvotes: 3

Views: 194

Answers (1)

Modzful
Modzful

Reputation: 177

You can use these methods to do this :

  • Padolsey custom filter (see Padolsey regexp: filter)

    Let's say you have <div class="exampleDiv">, you can catch the div element with $("div:regex(class, exa.*)"). (NB: exa.* is your regex...)

  • Native jQuery selectors

    $('[id^=start]') matches elements with id attribute starting with start $('[id$=end]') matches elements with id attribute ending with end

Upvotes: 2

Related Questions