current position:Home>What are the similarities and differences between jQuery and native JS?
What are the similarities and differences between jQuery and native JS?
2022-04-29 13:49:43【How's Kakashi doing】
hello hello, We learn to be original JS I have learned and mastered two ways to get and set text , Do you remember ? That's it innerHTML And innerText, Right , The use of these two basic native methods must have been somewhat confused ? Don't panic ! Now I'll take you to review these two methods .
For this article , I'll show you jQuery Method to get and set text content , towards jQuery Step into the abyss !!!
List of articles :
1.1 html() For content acquisition
1.2 html() Settings for content
1.3 innerHTML Set and get 【 Native JS Review and consolidate 】
1.3.1 innerHTML Acquisition of text content
1.3.2 innerHTML Setting of text content
2.1 text() For content acquisition
2.2 text() Settings for content
2.3 innerText Set and get 【 Native JS Review and consolidate 】
1.3.1 innerText Acquisition of text content
1.3.2 innerText Setting of text content
One :html() And innerHTML
html() yes jQuery Methods , It is equivalent to innerHTML, Both can be identified HTML label , Therefore, when printing, the element labels will be printed together
1.1 html() For content acquisition
We can get it directly without parameters , And the tags in the content will also get
<body>
<div>
<p> I am a text </p>
</div>
<script>
console.log($('div').html());
</script>
</body>
Output results :
You can see html() The label is also output
1.2 html() Settings for content
If you set it, you only need to set the parameter to the text we want to change
<body>
<div>
<p> I am a text </p>
</div>
<script>
$('div').html('1234567890');
</script>
</body>
Output results :
You can see that our text content has been changed to the content we want to set
1.3 innerHTML Set and get 【 Native JS Review and consolidate 】
Now let's review that the effect is equivalent to jQuery Of html() Methodical Native innerHTML
1.3.1 innerHTML Acquisition of text content
<body>
<div>
<p> I am a text </p>
</div>
<script>
var ele=document.querySelector('div')
console.log(ele.innerHTML);
</script>
</body>
Output results :
innerHTML The label will also be printed
1.3.2 innerHTML Setting of text content
<body>
<div>
<p> I am a text </p>
</div>
<script>
var ele=document.querySelector('div')
ele.innerHTML='123456'
</script>
</body>
Output results :
The text content has been changed to what we want to set
Two :text() And innerText
text() yes jQuery Methods , It is equivalent to innerText, They don't recognize HTML label , Therefore, the element labels will not be printed together when printing , Different from the previous two, we need to pay attention to !!
2.1 text() For content acquisition
We can get it directly without parameters , Be careful The difference In the content Labels won't get
<body>
<div>
<p> I am a text </p>
</div>
<script>
console.log($('div').text());
</script>
</body>
Output results :
The content was printed out , The label in the content is not printed
2.2 text() Settings for content
If you set it, you only need to set the parameter to the text we want to change
<body>
<div>
<p> I am a text </p>
</div>
<script>
$('div').text('1234');
</script>
</body>
Output results :
The text content is changed to the value we want to set
2.3 innerText Set and get 【 Native JS Review and consolidate 】
Then let's review that the effect is equivalent to jQuery Of text() Methodical Native innerText
1.3.1 innerText Acquisition of text content
<body>
<div>
<p> I am a text </p>
</div>
<script>
var ele=document.querySelector('div')
console.log(ele.innerText);
</script>
</body>
Output results :
innerText Won't type the label
1.3.2 innerText Setting of text content
<body>
<div>
<p> I am a text </p>
</div>
<script>
var ele=document.querySelector('div')
ele.innerText='123';
</script>
</body>
Output results :
The content is changed to the value you want to set
【 It's not easy to create , Give me a compliment before you go , thank you !!】
copyright notice
author[How's Kakashi doing],Please bring the original link to reprint, thank you.
https://en.qdmana.com/2022/119/202204291211305395.html
The sidebar is recommended
- How to create JavaScript custom events
- Is there any recommendation for wireless signal and wired signal power amplification circuit?
- Introduction to basic methods of math built-in objects in JavaScript
- 1000km pure electric endurance is meaningless? Then why does the car factory still try its best to extend the endurance?
- [let's implement a simple vite!] Chapter 4 - compiling single file components
- 3-11xss htmlspecialchars bypass demo
- How to conduct architecture design 𞓜 deeply reveal Alibaba cloud serverless kubernetes (2)
- Heapdump performance community special series 7: front door opener of large factory -- Application Practice of fluent
- 1、 HTML base tag
- Don't leave the crane unless necessary! A case of novel coronavirus nucleic acid positive was found in Heshan, Guangdong
guess what you like
[Architect (Part 20)] self defined template of scaffold and summary of phase I
How does JavaScript understand this algorithm
[live review] openharmony knowledge empowerment lesson 2, phase 5 - becoming a community talent
Understand the basic history and knowledge of HTTP
Influence of lazy loading of Web front-end training on Web Performance
Guangxi 2021 Guangxi landscape - blessing Lake Changshou Island
Responsive gulp Chinese network of web front end
Twaver-html5 basic learning (26) background
CSS learning notes [3] floating, not separated from document flow, inheritance and stacking
Webengine loading local html is invalid, and html is the dynamic address generated by JS, which can be solved
Random recommended
- Event handling of react
- Character coding knowledge that needs to be understood in front-end development
- 05. JavaScript operator
- 06. JavaScript statement
- Vue basics and some components
- Introduction to front-end Er excellent resources
- Node. Summary of methods of outputting console to command line in JS
- The beginning of passion, the ending of carelessness, python anti climbing, Jiageng, friends asked for MIHA's API and arranged y24 for him
- Technology sharing | test platform development - Vue router routing design for front-end development
- Node under windows JS installation detailed steps tutorial
- Layui built-in module (element common element operation)
- Excuse me, my eclipse Exe software has clearly opened to display the number of lines. Why is it useless
- It was revealed that Meila of Sea King 2 had less than ten minutes to appear, which was affected by negative news
- Vue element admin how to modify the height of component El tabs
- Bootstrap navigation bar drop-down menu does not take effect
- Vue Preview PDF file
- Geely joined the hybrid sedan market, and Toyota seemed even more hopeless
- Mustache template engine for exploring Vue source code
- Referer and referer policy and picture anti-theft chain
- Explain the "three handshakes" and "four waves" of TCP connection in detail
- Introduction to basic methods of math built-in objects in JavaScript
- JavaWeb Tomcat (III) httpservlet
- Vue Za wiper technical scheme
- Differences, advantages and disadvantages between HTTP negotiation cache Etag and last modified
- After taking tens of millions less, the management of Lenovo holdings took the initiative to reduce the salary by 70%
- What if Vue introduces this file and reports an error?
- Use Hikvision Web3 in vue3 2. Live broadcast without plug-in version (II)
- How to learn high-order function "zero basis must see"
- Detailed explanation of JS promise
- Cesium drawcommand [1] draw a triangle without talking about the earth
- The role of webpack cli in webpack packaging
- Action system of coco2d-x-html5
- Vxe table check box paging data memory selection problem
- [hand tear series] hand tear promise -- this article takes you to realize promise perfectly according to promise a + specification!
- QT use qdialog to realize interface mask (mask)
- Differences between JSP comments and HTML comments
- Bankless: Ethereum's data report and ecological highlights in the first quarter of 22 years
- Spring mvc07: Ajax research
- Understand the basic history and knowledge of HTTP
- Technology sharing | learning to do test platform development vuetify framework