You can use the startswith CSS3 selector to get those divs:
$('div[class^="project"]')
To check one particular element, you’d use .is()
, not hasClass
:
$el.is('[class^="project"]')
For using the exact /project\d/
regex, you can check out jQuery selector regular expressions or use
/(^|\s)project\d(\s|$)/.test($el.attr("class"))