jQuery Examples - $("p + ul")
Description
"$("p + ul")" Selects all elements matched by <ul> that follow a sibling element matched by <p>.
Syntax
Here is the simple syntax to use this selector −
$("element1 + element2")
Parameters
Here is the description of all the parameters used by this selector −
element1 − element
element2 − sibling element which comes after above element.
Returns
Like any other jQuery selector, this selector also returns an array filled with the found elements.
Example
<html>
<head>
<title>The Selector Example</title>
<script type = "text/javascript"
src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js">
</script>
<script type = "text/javascript" language = "javascript">
$(document).ready(function() {
/* Selects all elements matched by <ul> that follow a sibling element matched by <
p>.*/
$("p + ul").css("background-color", "yellow");
});
</script>
</head>
<body>
<h3>This is first list.</h3>
<ul>
<li><a id = "first" class="big" href="#">Big</a></li>
<li><a id = "first" class="medium" href="#">Medium</a></li>
<li><a id = "first" class="small" href="#">Small</a></li>
</ul>
<p>This is second list.</p>
<ul>
<li><a id = "first" class="big" href="#">Big</a></li>
<li><a id = "first" class="medium" href="#">Medium</a></li>
<li><a id = "first" class="small" href="#">Small</a></li>
</ul>
</body>
</html>
This will produce following result −
jqueryexamples_selectors.htm
Advertisements