Home Web Front-end JS Tutorial JQuery Study Notes Selector Four_jquery

JQuery Study Notes Selector Four_jquery

May 16, 2016 pm 06:49 PM
jquery study notes Selector

复制代码 代码如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script src="js/jquery-1.3.2.js"></script>
<script type="text/javascript"><!--
$(function(){
    $("#aContains").click(function(){
        $("div:contains('hello')").each(function(){
            $(this).css("background","red");                            
        })                        
    })
    $("#aEmpty").click(function(){
        $("div:empty").each(function(){
            $(this).html("EmptyDIV");                            
        })                        
    })
    $("#aHas").click(function(){
        $("div:has(p)").each(function(){
            $(this).css("background","red");                        
        })                        
    })
    $("#aParent").click(function(){
        $("div:parent").each(function(){
            $(this).css("background","red");                        
        })                        
    })
})
// --></script>
</head>

<body>
<div id ="div1">
    <p>hello word!</p>
</div>
<div id ="div2">
    hello
</div>
<div id ="div3" height="20px">
</div>
<div id ="div4"></div>

<a href="#" id="aContains">设置内容包含“hello”的节点红色背景颜色</a>
<a href="#" id="aEmpty">设置无内容的DIV内容设为EmptyDIV</a>
<a href="#" id="aHas">设置包含 p 节点的 div 节点红色背景颜色</a>
<a href="#" id="aParent">设置包含子节点的 div 节点红色背景颜色</a>
</body>
</html>

First of all, let’s explain the extracurricular knowledge points in this chapter
1.element.css("attributeName","value")
Description: used to set the style of element, in the example $(this) .css("background","red"); is to set the background of the node to red.
Now let’s get to the topic
1.$("TagName:contains('keyword')")
Description: Used to obtain the node collection containing keyword content in all TagName nodes
Return value: Array (Element);
2.$("TagName:Empty")
Description: Used to obtain the node collection with empty content in all TagName nodes
Return value: Array(Element);
3.$("TagName1:has(TagName2))
Description: Used to obtain the node set containing TagName2 child nodes among all TagName1 nodes
Return value: Array(Element);
4.$( "TagName:parent")
Description: Used to obtain the node set including child nodes in all TagName nodes
Return value: Array(Element);
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 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

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

Summary of commonly used file operation functions in PHP Summary of commonly used file operation functions in PHP Apr 03, 2024 pm 02:52 PM

Summary of commonly used file operation functions in PHP

How to tell if a jQuery element has a specific attribute? How to tell if a jQuery element has a specific attribute? Feb 29, 2024 am 09:03 AM

How to tell if a jQuery element has a specific attribute?

See all articles