Change DIV background
<html> <head> <script type="text/javascript" src="js/jquery-1.3.2.js"></script> <script type="text/javascript"> $(document).ready(function(){ function colorEm() { var $div = $("div"); $div.css("background", "red"); $div.slice(2, 4).css("background", "yellow"); } $("button").click(colorEm); }); </script> <style> div { width:40px; height:40px; margin:10px; float:left;} </style> </head> <body> <body> <button>Click the button</button> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> </body> </html>