Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select elements with attributes that start with something?

Tags:

html

jquery

css

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)

like image 838
Manuel Avatar asked Dec 13 '25 18:12

Manuel


1 Answers

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

like image 109
Modzful Avatar answered Dec 16 '25 09:12

Modzful



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!