0

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.

3 Answers 3

2

Try $('.maintext').each instead. Class names are case-sensitive.

Sign up to request clarification or add additional context in comments.

2 Comments

sorry for the typo. that is psuedo code to show what I what I am doing. my jQuery has the correct case, but still is not working at the basic selector level. $(".whatever") still does not select div class='whatever youwant' /div appreciate it,
It should be working perfectly then. Can you post more information (the context of the HTML, the context of the jQuery) so we can see potentially what's going on?
1

jQuery selectors are case sensitive. You have maintext in your HTML but mainText in the jQuery selector.

$('.maintext').each

Should work.

3 Comments

sorry for the typo. that is psuedo code to show what I what I am doing. my jQuery has the correct case, but still is not working at the basic selector level. $(".whatever") still does not select div class='whatever youwant' /div appreciate it,
Yes! it looks like it worked with just the first class name as you guys said. I found I had ended up with type="text/x-javascript" in the script tag, and once I removed it the script hit all the divs.
@omaether, that's because the browser doesn't recognise "x-javascript" so doesn't even run it. You should have type="text/javascript" though.
0

in your question, the HTML says maintext and the JS uses mainText (capital T).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.