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
  • 58,640
  • 98
  • 266
  • 407

2 Answers2

4

Wildcards in jQuery selectors

Simply use regular expressions in selectors:

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

You could use attribute selector.

$('div[id^="hello"]')
xdazz
  • 158,678
  • 38
  • 247
  • 274