3

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.

Rolando
  • 51,528
  • 92
  • 250
  • 377

2 Answers2

4

Wildcards in jQuery selectors

Simply use regular expressions in selectors:

$("div[id^=hello]").hide();
Community
  • 1
  • 1
Drakkainen
  • 1,136
  • 9
  • 25
3

You could use attribute selector.

$('div[id^="hello"]')
xdazz
  • 154,648
  • 35
  • 237
  • 264