Detailed explanation of jQuery method attributes

Detailed explanation of jQuery method attributes

1. Introduction to jQuery

What is jQuery and what does it do?

  • jQuery is used to simplify JS operations on DOM elements
  • jQuery cannot use DOM methods, and DOM cannot use jQuery methods

Usage characteristics of various selectors:

There are five basic selectors: $(" .#*,空格");

There are 4 types of relational selectors: $(“空格>+~ ”)

There are 8 basic filter selectors: $(" :first/:last/:even/:odd/eq(index)/:gt(index)/:lt(index)/:not(selector) ")

There are 4 content filter selectors: $(" :contains(text)/:empty/:has(selector)/:parent ")

There are 2 types of visibility filter selectors: $(" :hidden/:visible ")

There are 8 attribute selectors: ( " = = [ attribute ] , [ attribute = value ] , [ attribute ! = value ] , [ attribute = value ] , [ attribute ("==[attribute] , [attribute=value] [attribute!=value] , [attribute^=value]、[attribute ("==[attribute] , [attribute=value] [attribute!=value] [attribute=value] , [attribute=value] , [attribute*=value] , [attributeFilter1][attrbuteFilter2]==")

Sub-element filter selector (4 types) $( ":nth-child(index/even/odd) , :first-child , :last-child , :only-child" )

Form attribute filter selector (4 types) ${" :enabled/:disabled/:checked/:selected "}

Form selector (11 types) $(" :input/:text/:password/:radio/:checkbox/:submit/:image/:reset/:button/:file/:hidden ")

2. jQuery selector

2.1 Five basic selectors

    // 5 basic selectors $(".div"); // class selector $("div"); // tag selector $("#box"); // id selector $("*"); // wildcard selector $("div,p,img"); // merge selector

2.2 Four types of relationship selectors

    //4 types of relationship selectors $("div p"); //descendant selector $("div>p"); //child selector $("div+p"); //direct sibling selector $("div~p"); //simple sibling selector

2.3 8 basic filter selectors

// 8 basic filter selectors $(":first");//First element $(":last");//Last element $(":not(selector)");//Exclude selector $(":even");//Select even rows $(":odd");//Select odd rows $(":eq(index)");//Elements with index equal to index $(":gt(index)");//Elements with index greater than index $(":lt(index)");//Elements with index less than index

2.4 4 types of content filter selectors

        // 4 types of content filter selectors $(":contains(text)"); //Matches elements that contain the given text $(":empty"); //Matches all empty elements that do not contain child elements or text $(":has(selector)"); //Matches elements that contain the selector $(":parent"); //Matches elements that have child elements or text

2.5 Two types of visibility filter selectors

        // 2 types of visibility filter selectors $(":hidden"); // matches all invisible elements, or elements of type hidden $(":visible"); // matches all visible elements

2.6 8 types of attribute filter selectors

        // 8 types of attribute filter selectors $("[attribute]"); //Match elements with attribute attributes $("[attribute=value]"); //Match elements with attribute values ​​equal to value $("[attribute!=value]"); //Match elements with attribute values ​​not equal to value $("[attribute^=value]"); //Match elements with attribute values ​​starting with certain values ​​$("[attribute$=value]"); //Match elements with attribute values ​​ending with certain values ​​$("[attribute*=value]"); //Match elements with attribute values ​​containing certain values ​​$("[attributeFilter1][attrbuteFilter2]"); //Compound attribute filter selector, used when multiple conditions need to be met at the same time

2.7 Sub-element filter selectors (4 types)

        //Sub-element filter selector (4 types)
            $(":nth-child(index/even/odd)") //Select the index-th child element under each parent element $(":first-child"); //Select the first child element of each parent element $(":last-child"); //Select the last child element of each parent element $(":only-child"); //If an element is the only child element of its parent element, it will be matched

2.8 Form attribute filter selectors (4 types)

        //Form attribute filter selector (4 types)
            $(":enabled");//Select all enabled elements$(":disabled");//Select all disabled elements$(":checked");//Select all selected elements$(":selected");//Select all selected elements

2.9 Form selectors (11 types)

        // Form selector (11 types)
            $(":input");//Select all input/textarrea/select/button elements$(":text");//Select all single-line text boxes$(":password");//Select all password boxes$(":radio");//Select all radio buttons$(":checkbox");//Select all check boxes$(":submit");//Select all submit buttons$(":image");//Select all image buttons$(":reset");//Select all reset buttons$(":button");//Select all buttons$(":file");//Select all upload fields$(":hidden");//Select all invisible elements

3. DOM manipulation in jQuery

3.1 Text Operation

        // Text operation $("p").html(); // Equivalent to p.innerHtml in DOM;
        $("p").text();//Equivalent to p.innerText in DOM;

3.2 Value Operations

        // Value operation $("input:eq(5)").val(); //Equivalent to input.value in DOM;
        $("input:eq(6)").val("aaa"); //Set attribute value

3.3 Attribute Operation

 		// Attribute operation $("#box").attr('name'); //Get the name attribute $("#box").attr('name',"aaa"); //Add the name attribute and value $("#box").removeAttr('name'); //Delete the name attribute $("#box").prop('checked'); //When getting a single attribute, use prop to get false and true

3.4 Class Operations

    	// Class operation $("#box").attr("class","");//Get and set $("#box").addClass("class","");//Append class name $("#box").removeClass("class","");//Remove class name $("#box").removeClass();//Remove all class names $("#box").toggleClass("main");//Switch main class name $("#box").hasClass("main");//Is there a certain class name

3.5 Style Operation

	//Style operation $("#box").css("color"); //Read CSS style value $("#box").css({"propertyname":"value","propertyname":"value"}); //Set multiple styles at the same time

4. Node Operation

4.1 Traversing nodes

		 //Traverse nodes$("#box").children();//Get child nodes$("#box").children("div");//Get div child nodes$("#box").prev();//Find a brother immediately above$("#box").prevAll();//Find all brothers immediately above$("#box").prevAll("div");//Find all div brothers immediately above$("#box").next();//Find a brother immediately below$("#box").nextAll();//Find all brothers immediately below$("#box").nextAll("div");//Find all div brothers immediately below$("#box").parent();//Find parent node

4.2 Filter Nodes

    //Filter nodes $("ul").find(".a");//Search $("ul li").filter(".a");//Filter

4.3 Create, Insert, and Delete

    // Create, insert, delete var lis=$("<li title='aaa'>aaa</li>");//Create//Internally add parent.append(lis);//Add to the end of the parent box parent.prepend(lis);//Add to the head of the parent box//Externally add box.after(lis);//Add after the box box.before(lis);//Add before the box//Delete DOM elements $("ul").remove();//Completely delete, delete both ul and li $("ul").empty();//Just clear the contents of ul, ul still exists $("li").remove(".one");//Delete class="one" in li

5. jQuery Events

    // jQuery event // Difference from JS // window.onload and $(document).ready()
            //Difference 1: The former is executed after the page is fully loaded, while the latter is executed after the DOM is loaded. The latter takes precedence over the former. //Difference 2: When the former appears multiple times, the last one will overwrite the previous one. When the latter appears multiple times, they will be merged. //Difference 3: Is there an abbreviation: window has no abbreviation, document has an abbreviation. //Abbreviation: $().ready(function(){...})
                // $(function(){....})
        //Event binding: $(selector).on(event type, callback function)
        $("ul li").on("click",function(){alert(1);});	
    // jQuery and Ajax
            // get method $.get(url,data,success(response,status,xhr),dataType);
            // post method $.post(url,data,success(data, textStatus, jqXHR),dataType);

image-20211030195950325

Summarize

This article ends here. I hope it can be helpful to you. I also hope that you can pay more attention to more content on 123WORDPRESS.COM!

You may also be interested in:
  • JS JQuery obtains data-* attribute value method analysis
  • Analysis of JQuery style and attribute setting methods
  • Detailed explanation of the properties and methods of jQuery event objects
  • Detailed explanation of jQuery prototype properties and prototype methods

<<:  Web Design Tutorial (5): Web Visual Design

>>:  How to modify the "Browse" button of the html form to upload files

Recommend

Detailed tutorial on configuring nginx for https encrypted access

environment: 1 CentOS Linux release 7.5.1804 (Cor...

Detailed explanation of three ways to import CSS files

There are three ways to introduce CSS: inline sty...

Example code for css flex layout with automatic line wrapping

To create a flex container, simply add a display:...

Introduction to NFS service construction under Centos7

Table of contents 1. Server 2. Client 3. Testing ...

Detailed explanation of MySQL semi-synchronization

Table of contents Preface MySQL master-slave repl...

Detailed explanation of overflow-scrolling to solve scrolling lag problem

Preface If you use the overflow: scroll attribute...

jQuery plugin to implement accordion secondary menu

This article uses a jQuery plug-in to create an a...

Detailed explanation of prototypes and prototype chains in JavaScript

Table of contents Prototype chain diagram Essenti...

Centos7 implements sample code for restoring data based on MySQL logs

Introduction Binlog logs, that is, binary log fil...

Summary of problems encountered in the implementation of Vue plug-ins

Table of contents Scene Introduction Plugin Imple...

How to install FastDFS in Docker

Pull the image docker pull season/fastdfs:1.2 Sta...

CSS container background 10 color gradient Demo (linear-gradient())

grammar background: linear-gradient(direction,col...

Implementation of one-click TLS encryption for docker remote api

Table of contents 1. Change the 2375 port of Dock...

Difference between src and href attributes

There is a difference between src and href, and t...