1

in CSS, we can select multiple classes with same prefix like: 'pre-1','pre-2',... with this line of code:

[class^="pre-"]

Is there any way in Javascript that I can get the same result in Javascript? Thank you!

The result I want to achieve is for Javascript code.

cweiske
  • 30,033
  • 14
  • 133
  • 194
Lan Mai
  • 365
  • 1
  • 5
  • 18

1 Answers1

5

Use plain JavaScript

document.querySelectorAll('div[class^="pre-"]')

or

Use jquery starts with attribute selector Selector [name^="value"]

$('[class^="pre-"]')

More here

Working fiddle https://jsfiddle.net/66bw5u4h/88/

Erik Uggeldahl
  • 1,076
  • 11
  • 23
S M
  • 3,133
  • 5
  • 30
  • 59