jQuery Examples - $("strong + em")
Description
"$("strong + em")" Selects all elements matched by <em> that immediately follow a sibling element matched by <strong>.
Syntax
Here is the simple syntax to use this selector −
$("style-name1 + style-name2")
Parameters
Here is the description of all the parameters used by this selector −
style-name1 − style name of an element
style-name2 − style name of the sibling of 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 <em> that immediately follow a
sibling element matched by <strong>.*/
$("strong + em").css("background-color", "yellow");
});
</script>
</head>
<body>
<strong>First</strong>
<em>Second</em>
<em>Third</em>
<em>Fourth</em>
<strong>Fifth</strong>
<em>Sixth</em>
</body>
</html>
This will produce following result −