Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery .addclass to multiple div

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");});
like image 931
Ryan Parker Avatar asked Oct 02 '13 01:10

Ryan Parker


1 Answers

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.

like image 65
Walter Gandarella Avatar answered Sep 22 '22 17:09

Walter Gandarella