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
?
class selector selects all elements with the specific class. The class refers to the class attribute of an HTML element. The class attribute is used to set a particular style for several HTML elements. Note: Do not start a class attribute with a number.
ID and Element selector are the fastest selectors in jQuery.
jQuery selectors allow you to select and manipulate HTML element(s). jQuery selectors are used to "find" (or select) HTML elements based on their name, id, classes, types, attributes, values of attributes and much more.
A - A jQuery Selector is a function which makes use of expressions to find out matching elements from a DOM based on the given criteria. B - jQuery selectors are used to select one or more HTML elements using jQuery. C - jQuery selectors start with the dollar sign and parentheses - $() D - All of the above.
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'If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With