Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select jquery elements containing a certain character string?

Tags:

jquery

Say I have the following:

<div id="hellokat"></div>
<div id="hellodog"></div>
<div id="byekat"></div>
<div id="byedog"></div>

I know I can select divs individually with $('#hellokat') and $('hellodog'), but I want to select all divs containing "hello" at the beginning of their ids at the same time.

like image 233
Rolando Avatar asked Dec 11 '25 09:12

Rolando


1 Answers

Wildcards in jQuery selectors

Simply use regular expressions in selectors:

$("div[id^=hello]").hide();
like image 130
Drakkainen Avatar answered Dec 12 '25 21:12

Drakkainen



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!