Review of JQuery basic syntax (1) -- selectors, JQuery object properties and methods

Posted by Zaynt on Thu, 26 Dec 2019 16:20:40 +0100

JQuery introduction

JQuery is a fast and concise JavaScript framework, which is another excellent JavaScript code base (or JavaScript framework) after Prototype. The purpose of jQuery design is "write Less, Do More", that is to advocate writing less code and doing more. It encapsulates common JavaScript function code, provides a simple JavaScript Design pattern, optimizes HTML document operation, event processing, animation design and Ajax interaction.
You can see that JQuery requires a basic knowledge of JavaScript.

Three selectors

//Get elements from element id
 var btn=$("#btn");
//Get elements from element class
var btn=$(".btn");
//Get element from element label
var btn=$(button);
//Select all labels
var all=$("*");

See jQuery objects who array objects

JQuery object methods and properties

            var divhtml=$("#div1").html(); / / get the sub character node value

            //If only text is used for text operation, html is used for style operation
            var divtext=$("#div1").text(" modify ");

            var btn=$("#btn");
            //The attr() function takes one parameter to get other properties.
            //The attr() function takes two parameters to modify the property.
            console.log(btn.attr("value","No more?"));
            //The css() function takes one parameter to get other properties.
            //The css() function has two parameters to modify the properties.
            //Modify multiple

            //There are three types of attributes for JQuery label objects

            //The array object traversed by $. each() generates the primitive dom object
            var divs=$("div");
            divs.removeClass();//Delete style
            divs.addClass("bb");//Chain structure can be used
            divs.each(function () {


Topics: JQuery Javascript less