How to implement a style behavior to all specific type of HTML element on the page using jQuery?

Posted by Poster under jQuery category on | Views : 3592
This is done with the help of selector.

<script type="text/javascript">
$("div").css("border", "1px solid gray");
$("div > p").css("background", "green");
$("p").css("color", "blue");
$("input:text", document.forms[0]).css("border", "1px solid red");

In the above code snippet,

The 1st line will select all the div element of the page and add the border style.
The 2nd line will select all the p element which is only inside the div and apply the background color
The 3rd line will select all the p element irrespective of they are inside the div or directly inside the body and will apply the color style. (This will cover p element inside the div as well).
The 4the line will select all Text input field in the first form and apply the border style.

Comments or Responses

Login to post response