This is done with the help of selector.
$("div").css("border", "1px solid gray");
$("div > p").css("background", "green");
$("input:text", document.forms).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.