I am trying to apply the class ".lightGray" that i defined earlier on to div 4,5,7,and this current one. Not sure what I am doing wrong!
$("#Div8").click(function(){$("#Div4", "#Div5","#Div7","#Div8").addclass(".lightGray");});
I am trying to apply the class ".lightGray" that i defined earlier on to div 4,5,7,and this current one. Not sure what I am doing wrong!
$("#Div8").click(function(){$("#Div4", "#Div5","#Div7","#Div8").addclass(".lightGray");});
Use .addClass("lightGray");
as .addClass() takes className not .className
and change
$("#Div4,#Div5,#Div7,#Div8")
to
$("#Div4 ,#Div5, #Div7 ,#Div8")
you code becomes
$("#Div8").click(function(){
$("#Div4 ,#Div5 ,#Div7 ,#Div8").addClass("lightGray");
^ //remove dot from here
});
$("#Div4 ,#Div5 ,#Div7 ,#Div8")
this is correct selector.Check updated code. –
Paryavi .addClass()
doc, but didin't notice that OP is using addclass
! –
Swarey addClass(arrayofElements)
. I tried to store it like arrayofElements=["#id1","#id"]
but doesn't work. –
Chopping when you add a class you do not need the dot.
try this instead
$("#Div8").click(function(){$("#Div4, #Div5, #Div7, #Div8").addClass("lightGray");});
In all DIVS these I put a default class: changeClass
, and maintain their individual IDS.
A instead of doing $("#Div4","#Div5","#Div7","#Div8")
would suffice to make $(".changeClass).addClass("lightGray");
Classes can be used in more than one element at the same time and thus can manipulate several of these elements at once, saving time and lines of code.
You have made four separate selectors instead on one selector.
The commas should be inside the string:
$("#Div4,#Div5,#Div7,#Div8")
The method name is addClass
, not addclass
, and there shouldn't be a period before the class name:
$("#Div8").click(function(){$("#Div4,#Div5,#Div7,#Div8").addClass("lightGray");});
Try this.
$("#Div8").click(function(){
$("#Div4,#Div5,#Div7,#Div8").addClass("lightGray"); //removed exra quotes from selecter
//removed dot(.) from class name
//Changed *addclass* to **addClass**
});
© 2022 - 2024 — McMap. All rights reserved.
.addClass()
. – Swarey