Home Web Front-end JS Tutorial Example of selecting elements using jQuery content filtering selector_jquery

Example of selecting elements using jQuery content filtering selector_jquery

May 16, 2016 pm 05:36 PM
jquery filter Selector

Copy code The code is as follows:

<html xmlns="http://www.w3.org /1999/xhtml">
<head>
<!--
Content filter selector: Get the element based on the text content in the element or the characteristics of the sub-elements it contains, and its text content can Fuzzy or absolute matching for element positioning
Detailed explanation of jQuery selector
According to the different elements in the obtained page, jQuery selectors can be divided into four categories: basic selector, hierarchical selector, filter selector and form selector. Categories. Among them, there are 6 types of filter selectors: simple filter selector, content filter selector, visibility filter selector, attribute filter selector, child element filter selector, and form object attribute filter selector
-->
<title></title>
<!-- Use the jQuery content filter selector to select elements: In the page, create four <div> tags as needed, and add Create a new <span> tag in the <div>, enter content (or be empty) in the remaining <div> tags, obtain the specified element through the content filter, and display it on the page. -->
<script src="jquery-1.9.1.js" type="text/javascript"></script>
<style type="text/css">
body{font-size:12px;text-align:center}
div{float:left;border:solid 1px #ccc;margin:8px;width:65px;height:65px;display:none}
span{float:left;border:solid 1px #ccc;margin:8px;width:45px;height:45px;background-color:#eee}
</style>
<script type= "text/javascript">
$(function () { //Display elements containing the given text
$("div:contains('A')").css('display','block ');
})
$(function(){ //Display all empty elements that do not contain child elements or text
$('div:empty').css('display','block ');
})
$(function () { //Display the elements matched by the selector
$('div:has(span)').css('display', 'block ');
})
$(function () { //Display elements containing child elements or text
$('div:parent').css('display', 'block');
})
</script>
<!-- Note: In the:contains(text) content filter selector, if you are looking for letters, there is a case difference-->
</head>
<body>
<div>ABCD</div>
<div><span></span></div>
<div>EFAH</div>
<div></div>
</body>
</html>
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)

Detailed explanation of jQuery reference methods: Quick start guide Detailed explanation of jQuery reference methods: Quick start guide Feb 27, 2024 pm 06:45 PM

Detailed explanation of jQuery reference methods: Quick start guide

How to open filtered duplicate files in Quark How to open filtered duplicate files in Quark Mar 01, 2024 am 11:25 AM

How to open filtered duplicate files in Quark

How to use PUT request method in jQuery? How to use PUT request method in jQuery? Feb 28, 2024 pm 03:12 PM

How to use PUT request method in jQuery?

How to remove the height attribute of an element with jQuery? How to remove the height attribute of an element with jQuery? Feb 28, 2024 am 08:39 AM

How to remove the height attribute of an element with jQuery?

jQuery Tips: Quickly modify the text of all a tags on the page jQuery Tips: Quickly modify the text of all a tags on the page Feb 28, 2024 pm 09:06 PM

jQuery Tips: Quickly modify the text of all a tags on the page

Use jQuery to modify the text content of all a tags Use jQuery to modify the text content of all a tags Feb 28, 2024 pm 05:42 PM

Use jQuery to modify the text content of all a tags

Chinese character filtering: PHP regular expression practice Chinese character filtering: PHP regular expression practice Mar 24, 2024 pm 04:48 PM

Chinese character filtering: PHP regular expression practice

Understand the role and application scenarios of eq in jQuery Understand the role and application scenarios of eq in jQuery Feb 28, 2024 pm 01:15 PM

Understand the role and application scenarios of eq in jQuery

See all articles