Search code examples
javascriptjquerycssonloaddynamic-css

apply css on page load to all DIV elements


Is there a way to format all my tags in a page, on page load, with a css property like this ?

border:1px #000000;

Also, on hover of any of the DIV, the border should change to this :

border : 1px #00800;

I want both these properties, regular CSS and on-hover CSS to be applied on page load, dynamically.


Solution

  • This code snippet might work:

    $(document).ready(function()//When the dom is ready or just add it if you already have a .ready function
    {
      $("#div").css("border","1px #000000");
      $('#div').mouseover(function (e) {
       $("#div").css("border","1px #00800");
      });
    });