$(document).ready(function () { var css = { 'color': 'Aqua', 'background-color': 'Yellow' }; $("#divParent").click(function () { $("div").parent().css(css); }); $("#divP").click(function () { $("p").parent().css(css); }); $("#divSpan").click(function () { $("span").parent().css(css); }); $("#divEm").click(function () { $("em").parent().css(css); }); });
<html> <head> <title>parent</title> </head> <body> <div> This is Div element. <p>This is paragraph element. It is inside Div element.<br> <span>This is span element. It is inside paragraph element.<br> <em>This is emphasize element. It is inside span element.</em> </span> </p> </div><br /> <input type="button" id="divParent" value="Parent of Div" /> <input type="button" id="divP" value="Parent of P" /> <input type="button" id="divSpan" value="Parent of Span" /> <input type="button" id="divEm" value="Parent of EM" /> <input type="button" id="reset" value="Reset" onclick="location.reload();" /> </body> </html>