Skip to content Skip to sidebar Skip to footer

JavaScript Selector By Class Prefix?

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 re

Solution 1:

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/


Post a Comment for "JavaScript Selector By Class Prefix?"