JQuery: loop through elements with more than one css class name that share only the first class name
I'm trying to use JQuery to loop through several div's with more than one class name, that all have the same first css class name and each one has a different second class name, e.g.
<div class="maintext blue"> </div>
<div class="maintext purple"> </div>
<div class="maintext chartreuse"> </div>
<div class="maintext puce"> </div>
<div class="maintext lime"> </div>
In JQuery I have tried
$(".mainText").each(function (i)
$(".mainText.*").each(function (i)
$(".mainText" *).each(function (i)
$(".mainText .*").each(function (i)
But it will not select any of the divs with class="mainText ..."
thanks for 开发者_运维问答considering the question.
Try $('.maintext').each
instead. Class names are case-sensitive.
jQuery selectors are case sensitive. You have maintext
in your HTML but mainText
in the jQuery selector.
$('.maintext').each
Should work.
in your question, the HTML says maintext
and the JS uses mainText
(capital T).
精彩评论