0

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
  • 28,704
  • 13
  • 124
  • 186
Lan Mai
  • 345
  • 3
  • 15

1 Answers1

4

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
  • 936
  • 9
  • 22
S M
  • 2,939
  • 5
  • 28
  • 54