0

I want to change all the background-color of all divs with the class Liregion2. I just want to change the div background color, not li. My code only changes one div element, though! How can I make it affect all of them?

Here is my HTML5 code:

<div class = "Liregion2" id = "LineBock1" style ="padding-bottom:3%;padding-left:10%;background-color:#ff9900"> 
 <li>
   <a href="#" id = "FirstLine" style="color:#fff;text-decoration: none" >1號線</a>
 </li>
</div>  
<div class = "Liregion2" id = "LineBock2" style ="padding-bottom:3%;padding-left:10%;">             
 <li>
   <a href="#" id = "SecondLine" style="color:#009999;text-decoration: none" >2號線</a>
 </li>
</div>  
<div class = "Liregion2" id = "LineBock3" style ="padding-bottom:3%;padding-left:10%;"> 
 <li>
   <a href="#" id = "ThirdLine" style="color:#ff3366;text-decoration: none" >3號線</a>
 </li>
</div>  
<div class = "Liregion2" id = "LineBock4" style = "padding-left:10%;">  
 <li>
  <a href="#" id = "ForthLine" style="color:#0066ff;text-decoration: none" >4號線</a>
 </li>
</div>  

And here is the JQuery:

$('#FirstLine').click(function(){
    $('.Liregion2').each(function( index , element  ){
            $(element).css("background-color" , "transparent");
    });     
    event.stopPropagation(); 
});
Mike Precup
  • 4,148
  • 21
  • 41
Kim Wong
  • 2,027
  • 4
  • 17
  • 22
  • Create a jsfiddle.net – Dejan.S Aug 02 '14 at 15:46
  • 1
    `css` iterates through the collection behind the scenes, there is no need to use a `each` loop. Also your markup is invalid, `li` should be child of an `ul`/`ol` element. – Ram Aug 02 '14 at 15:47
  • You are using inline css and inline css cann't be overridden,secondly you have problems in your markup you are using
  • inside div its not possible like this you would have to use it inside
    .Kindly fix your issues.write css in seperate style sheet and then include it as a class or as a id selector rather than using inline styles.
  • – Husrat Mehmood Aug 02 '14 at 15:55
  • @kimWong Provide jsfiddle.net link – Rashmin Javiya Aug 02 '14 at 16:01