How to change CSS settings of all DIVs with jQuery

0

I need to change the color of background , the color of the texts and the links of all the DIVs of a site . I was able to do this in JavaScript with the following code:

<script type="text/javascript">
function altoContraste() {
        var divs = document.getElementsByTagName("div");
        var links = geral.getElementsByTagName("a");


    for (var i = 0; i < divs.length; i++) {
         divs[i].style.background= '#000';
         divs[i].style.color= '#FFF';

    }
    for (var i = 0; i < links.length; i++) {
         links[i].style.color = '#FF0';
    }


}
</script>

But I need to do this using jQuery, I do not understand jQuery, but I researched in some places how to do it and I got to the following code:

<script>
$(".altoContrase").click( 
$("div").each(function() {
$(this).css({
'background': '#000', 'color': '#FFF'
})
});
</script>

Why is it not working? What should I do to be able to do this? In the jQuery code I can not change the color of links .

    
asked by anonymous 26.09.2014 / 21:55

1 answer

2

like this:

<script>
$(document).ready(function(){
   $('.altoContraste').click(function(){
      $('div').css('background-color', '#000');
      $('div').css('color', '#FFF');
      $('a').css('color', '#FF0');
   });
});
</script>

Remember that in your html there should be some button or tag that has the high class Contrast

    
26.09.2014 / 22:13