parent (:parent)
In this chapter you will learn:
- Description and Syntax for parent selector
- Examples for parent selector
- How to get parent element for a paragraph element
Description and Syntax
$(':parent')
selects all elements that are the parent of another element, including text nodes. The child elements include text nodes.
Examples
$(':parent')
selects all elements that are the parent of another element, including text nodes$('td:parent')
selects all<td>
elements that are the parent of another element, including text nodes
The following code selects the table row.
<html><!--from ja va 2 s. co m-->
<head>
<script src="http://java2s.com/style/jquery-1.8.0.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("td:parent").fadeTo(1500, 0.3);
});
</script>
</head>
<body>
<body>
<table border="1">
<tr><td>Value 1</td><td></td></tr>
<tr><td>Value 2</td><td></td></tr>
</table>
</body>
</html>
Parent of a paragraph
The following code selects the parent of the paragraph.
<html><!-- j a v a 2 s .c o m-->
<head>
<style>
.test{ border: 1px solid red; }
</style>
<script src="http://java2s.com/style/jquery-1.8.0.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("p:parent").addClass("test");
});
</script>
</head>
<body>
<div><p>paragraph in div</p></div>
<div>div</div>
</body>
</html>
Next chapter...
What you will learn in the next chapter:
- Description and Syntax for Contains text selector
- Examples for Contains text selector
- How to remove an element by its contents.
- Mark under line by content