Home Web Front-end JS Tutorial Usage examples and precautions when the selector contains spaces_jquery

Usage examples and precautions when the selector contains spaces_jquery

May 16, 2016 pm 05:27 PM
space Selector

Principle explanation:

var $t_a=$(".test :hidden") //The space indicates that the class is selected as the hidden element in test;
var $t_a =$(".test:hidden")//Without spaces, it means selecting hidden elements with class test;

Example:
Copy code The code is as follows:

<html>
<head>
<script type=" text/javascript" src="jquery-1.3.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function (){
var $a1=$(".test :hidden");
var $a2=$(".test:hidden");
alert($a1.length " " $a2 .length)
})
</script>
<style>
</style>
</head>
<body>
&lt ;div class="test" style="display:none;">
<p style="display:none">dddddddd</p>
<p style="display:none" >dddddddd</p>
</div>
<div class="test" style="display:none">
</div><div class="test " style="display:none"></div>
<body>
</html>

The output results are: 2 and 3 respectively;
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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What does a space mean in mysql? What does a space mean in mysql? Jul 20, 2023 pm 05:17 PM

What does a space mean in mysql?

The difference between full-width spaces and half-width spaces The difference between full-width spaces and half-width spaces Mar 25, 2024 pm 12:45 PM

The difference between full-width spaces and half-width spaces

How to replace spaces in vue How to replace spaces in vue Dec 22, 2022 am 09:40 AM

How to replace spaces in vue

Use the :nth-child(n+3) pseudo-class selector to select the style of child elements whose position is greater than or equal to 3 Use the :nth-child(n+3) pseudo-class selector to select the style of child elements whose position is greater than or equal to 3 Nov 20, 2023 am 11:20 AM

Use the :nth-child(n+3) pseudo-class selector to select the style of child elements whose position is greater than or equal to 3

What is the difference between full-width spaces and half-width spaces? What is the difference between full-width spaces and half-width spaces? Mar 15, 2024 pm 03:49 PM

What is the difference between full-width spaces and half-width spaces?

From beginner to proficient: Master the skills of using is and where selectors From beginner to proficient: Master the skills of using is and where selectors Sep 08, 2023 am 09:15 AM

From beginner to proficient: Master the skills of using is and where selectors

What to do if the javascript selector fails What to do if the javascript selector fails Feb 10, 2023 am 10:15 AM

What to do if the javascript selector fails

Sharing of practical techniques for replacing spaces in Golang Sharing of practical techniques for replacing spaces in Golang Mar 13, 2024 am 09:15 AM

Sharing of practical techniques for replacing spaces in Golang

See all articles