jQuery Selector How to - Set style to all children div using children method








Question

We would like to know how to set style to all children div using children method.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-2.1.0.js'></script>
<script type='text/javascript'>
$(window).load(function(){<!--from  w ww.  j  a va 2s .  co m-->
    $('#main').children().css({"background":"red"});
});
</script>
</head>
<body>
  <div id="main">
    <div id="one">Images 1</div>
    <div id="two">Images 2</div>
  </div>
</body>
</html>

The code above is rendered as follows: