<html>
<head>
<script type = "text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js">
</script>
<script type="text/javascript" language ="javascript">
$(document).ready(function()
{
$("li").eq(1).css("background-color","blue");
});
</script>
</head>
<body>
<div>
<ul>
<li> Reema </li>
<li> Seema </li>
<li> Rajesh </li>
<li> Anjali </li>
<li> Sunil </li>
<li> Rohan </li>
</ul>
</div>
</body>
</html>
<html>
<head>
<script type = "text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js">
</script>
<script type="text/javascript" language ="javascript">
$(document).ready(function()
{
$("li").eq(3).css({"color":"red","background-color":"yellow"});
});
</script>
</head>
<body>
<div>
<ul>
<li> Reema </li>
<li> Seema </li>
<li> Rajesh </li>
<li> Anjali </li>
<li> Sunil </li>
<li> Rohan </li>
</ul>
</div>
</body>
</html>
Setting the width of the first division element while the rest of the elements have their width set by the CSS.
<html>
<head>
<script type = "text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js">
</script>
<script type="text/javascript" language ="javascript">
$(document).ready(function()
{
$("div:first").width(80);
$("div:first").css("background-color","grey");
});
</script>
<style>
div{width:50px; height:20px; float:center; margin:3px; background:red; cursor:pointer;}
</style>
</head>
<body>
<div></div>
<div>One</div>
<div>Two</div>
<div>Three</div>
</body>
</html>
Methods | Description |
---|---|
css(name) | A style is returned on the first matched element. |
css(name,value) | A single style value is set on all the matched elements. |
css(properties) | A key/value object is set as style properties to all matched elements. |
height(val) | It gets the current computed, pixel, height of the first matched element. |
innerHeight() | It gets the inner height i.e. the border is excluded and the padding is included for the first matched element. |
innerWidth() | It gets the inner width i.e. the border is excluded and the padding is included for the first matched element. |
offset() | A jQuery collection is returned with the positioned parent of the first matched element. |
outerHeight([margin]) | It gets the outer height i.e. it includes the border and exclude the padding for the first matched element. |
outerWidth([margin]) | It gets the outer width i.e. it includes the border and exclude the padding for the first matched element. |
position() | It gets the top and left position of an element relative to its offset parent. |
scrollLeft(val) | The scroll left offset is set when a value is passed in. |