开发者

JQuery: loop through elements with more than one css class name that share only the first class name

开发者 https://www.devze.com 2023-02-03 14:06 出处:网络
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.

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).

0

精彩评论

暂无评论...
验证码 换一张
取 消