For whatever reason I have these classes called .main_sub1, .main_sub2 etc. Never mind why I can’t have .main .sub.
Is there a way with jQuery, sort of in the way it is possible to do with attributes, to get the classes containing main?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Using
$("[class^=main]")will select all elements whose classname starts with ‘main’. Take a look at jQuery docs about selectors, there are a lot of other variations you can use, for example:[class*=main]will select elements whose classname contains ‘main’[class~=main]will select elements whose classname has the word ‘main’ (delimited with spaces)[class$=main]will select elements whose classname ends in ‘main’