In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article will give you a detailed explanation on how jquery works. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.
1. JQuery is a fast, compact, feature-rich JavaScript library. JQuery makes it easier to traverse and manipulate HTML documents, event handling, and animation.
The code for jQuery will run exactly the same in all major browsers, including Internet Explorer 6!
2. You can download a copy of the jQuery library or introduce it from CDN (content distribution network) (such as BootCDN or Baidu CDN). CDN on BootCDN will be used. To start using jQuery, we first need to add it to the header of our HTML document using the script tag.
It is a good practice to wait for the HTML document to be fully loaded and ready before using it. To do this, we use the ready event of the document (document) object:
$is used to access jQuery. From here, the code accesses the document object and defines the function to call when the ready event of the document is triggered. This prevents any jQuery code from running before the document is loaded. We have a convenient shortcut that is equivalent to the above code:
3. Now that we have introduced the jQuery library into our head section and have defined document-ready events, we can start our first jQuery operation! Let's change the content of the div element.
In the above code, after the page document is ready, change the HTML of the element of id= "start" to "Let's go, Sao Nian!" .
4. JQuery is used to select (find) HTML elements and perform "operations" on them.
Selector is a selector for finding HTML elements. Action is the action to be performed by the desired element.
JQuery uses CSS selector syntax to select elements.
5. Select
The jQuery selector begins with a dollar sign and parentheses: $(). Note: all symbols in jQuery are English symbols. The most basic selector is the element selector, which selects all elements based on the element name.
Then there are the id and the class selector, which select the element by id and class name:
You can also use the following syntax for selectors:
Selectors make it easier to access HTML DOM elements than pure JavaScript.
6. Common selector
7. Attributes that can be assigned to HTML elements can be easily manipulated by jQuery. For example, the href,src,id,class,style attribute of an element. The attr () method is used to get the value of the property.
The attr () method also allows us to set a value for the property through the second parameter.
8. Delete attributes
You can also remove attributes from the HTML element. The removeAttr () method is used to delete any attributes of an element.
9. You can manipulate the contents of the HTML element through jQuery. The html () method is used to get the contents of the selected element, including the HTML tag.
Notice that the HTML tag is also returned. If you only need text content and do not need HTML tags, you can use the text () method:
The html () and text () methods can be used for all HTML elements that contain content.
Set content-you can use the html () and text () methods to change the content of the HTML element.
The above code changes the content of the element of id= "test" to "hello!".
If the content you set contains the HTML tag, you should use the html () method instead of text ().
10. Val () method
The val method allows us to get and set the values of form fields, such as text boxes (input), drop-down lists (select), and so on.
Similarly, you can set the value of this field by passing parameters in the val () method. Getting and setting the value of a form field is useful when you need to handle form events and validation.
11. The summary is as follows:
12. Add content
JQuery has methods for adding new content to selected elements without deleting existing content:
You can also insert content with a HTML tag.
13. The easiest way to create new HTML elements using jQuery is as follows:
The above code creates a new
Element that contains the text Hi and assigns it to a variable named txt.
You can add this variable to our HTML as a parameter to the above method
This will insert the newly created after the # demo paragraph
element. You can also specify multiple elements as parameters for the before (), after (), append (), prepend () methods by using comma separation, for example: $("# demo"). Append (var1,var2,var3).
The syntax for creating elements mentioned above can be used to create any new HTML element, for example, $("") can create a new div.
14. Add CSS
The addClass () method adds one or more classes to the selected element.
To specify multiple classes in the addClass () method, simply separate them with spaces. For example, $("div"). AddClass ("class1 class2 class3").
This is the end of the article on "how jquery works". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.