Home > Web Front-end > Front-end Q&A > What does > in jquery mean?

What does > in jquery mean?

青灯夜游
Release: 2022-03-01 18:26:29
Original
2304 people have browsed it

In jquery, ">" is a child element selector, which can only select child elements of a certain element; the syntax is "$("E > F")", where E is the parent element, and F is a sub-element, which means that all sub-elements F under the E element are selected.

What does > in jquery mean?

The operating environment of this tutorial: windows7 system, jquery1.10.2 version, Dell G3 computer.

In jquery, ">" refers to a sub-element selector, which is a type of hierarchical selector.

Child element selector (E>F)Only the child elements of a certain element can be selected, where E is the parent element and F is the child element, where E> What F represents is that all sub-elements F under the E element are selected.

Syntax:

$("E > F")
Copy after login

All selectors in jQuery begin with a dollar sign: $().

Return value: Return the matching result set

Example:

<!DOCTYPE html>
<html>
	<head>
		<script type="text/javascript" src="js/jquery-1.10.2.min.js"></script>
		<script>
			$(document).ready(function() {
				$("#main > *").css("border", "3px double red");
			});
		</script>
		<style>
			body {
				font-size: 14px;
			}

			span#main {
				display: block;
				background: yellow;
				height: 110px;
			}

			button {
				display: block;
				float: left;
				margin: 2px;
				font-size: 14px;
			}

			div {
				width: 90px;
				height: 90px;
				margin: 5px;
				float: left;
				background: #bbf;
				font-weight: bold;
			}

			div.mini {
				width: 30px;
				height: 30px;
				background: green;
			}
		</style>
	</head>
	<body>
		<span id="main">
			<div></div>
			<button>Child</button>
			<div class="mini"></div>
			<div>
				<div class="mini"></div>
				<div class="mini"></div>
			</div>
			<div><button>Grand</button></div>
			<div><span>A Span <em>in</em> child</span></div>
			<span>A Span in main</span>
		</span>
	</body>
</html>
Copy after login

Analysis:

$ ("#main > *").css("border", "3px double red");

will match the child elements in the span element and must be the first in the child element collection An element, the following are the matching elements (purple)

What does > in jquery mean?

[Recommended learning: jQuery video tutorial, web front-end]

The above is the detailed content of What does > in jquery mean?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template