What's the difference between jQuery and JS?
This article will explain in detail what is the difference between jQuery and JS, the content of the article is of high quality, so the editor will share it with you for reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.
1 positioning element
JS
Document.getElementById ("elemt")
JQuery
$("# elemt") / / locate via id
$(".elemt") / / locate via class
$("div") / / locate through the tag
Note that the result returned by JS is this element, and the result returned by jQuery is an object of JS. In the following example, it is assumed that the element elemt has been located.
2 change the content of the element
JS
Elemt [XSS _ clean] = "test"
JQuery
Elemt.html ("test")
3 show hidden elements
JS
Elemt.style.display = "none"
Elemt.style.display = "block"
JQuery
Elemt.hide ()
Elemt.show ()
Elemt.toggle (); / / switch between showing and hiding
4 gain focus
JS and jQuery are the same, both elemt.focus ()
5 assign values to the form
JS
Elemt.value = "test"
JQuery
Elemt.val ("test")
6 get the value of the form
JS
Alert (elemt.value)
JQuery
Alert (elemt.val ())
7 the setting element is not available
JS
Elemt.disabled = true
JQuery
Elemt.attr ("disabled", true)
8 modify element style
JS
Elemt.style.fontSize=size
JQuery
Elemt.css ('font-size', 20)
JS
Elemt.className= "test"
JQuery
Elemt.removeClass ()
Elemt.addClass ("test")
9 Ajax
JS
Create your own objects and deal with such messy issues as browser compatibility.
JQuery
Get ("elemt.php?a=1&b=2", recall)
Postvalue = "a=b&c=d&elemt=123"
$.post ("elemt.php", postvalue, recall)
Function recall (result) {
Alert (result)
/ / if json is returned, do the following
/ / result = eval ('('+ result +')')
/ / alert (result)
}
10 determine whether the check box is selected
JQuery
If (elemt.attr ("checked") = = "checked")
Note: xxx.attr ("checked") = = true is not available.
About what is the difference between jQuery and JS to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.