Difference: JavaScript is a language, and jQuery is a framework based on the JavaScript language. The method of javascript operating style can only obtain the inline style, not the embedded or external one; the method of JQUERY operating style can be inline or embedded.
The operating environment of this tutorial: Windows 7 system, ECMAScript version 5, Dell G3 computer.
1. Essential differences:
1. Everyone knows that js is a web scripting language, similar to java, which is a common development language;
2. jQuery is a front-end framework encapsulated based on js language;
So the most essential difference is that js is a language, and jQuery is a framework based on this language. In addition to the most essential differences, there are also some differences in usage.
2. Usage differences:
1. In appearance, jQuery objects have one more "$()" layer than js objects. Vest, this is the most intuitive difference;
2. Operation content
①. Non-form elements (if it is text, use the text method, if it is Use the html method for html code)
Example: p.text();——If there are no parameters, it will be the value
p.text("aaaa");——With parameters In the case of
p.html();——In the case of no parameters, it is the value
p.html("aaaa");——In the case of parameters, it is Assignment
[Recommended tutorial: jq tutorial]
②. Form element
JS: p.value;——Value; p.value = xxx;——Assignment
JUQERY: p.val();——Without parameters, it is a value, and with parameters, it is an assignment.
************************************************ *************************
3. Operation attributes
are used for operations in JS The attribute method is
p.setAttribute("",""); - set attributes and modify attributes
p.removeAttribute(""); - remove attributes within quotation marks Write an attribute name
p.getAttribute();——Get attributes
Methods used to operate attributes in JQUERY
Add attributes: p.attr("test" ,"aa");——Add parameters to this attr method, the attribute name is test, and the attribute value is aa
Remove the attribute: p.removeAttr("test");——Remove test Strip attributes
Get attributes: p.attr("test");——Just write the name of an attribute directly in the attr method
******** *************************************************** *********
4. Operation style
The keyword of operation style in JS is style
Example: p. style.backgroundColor = "red";——Set the background color of this p to red
The keyword for operating styles in JQUERY is css
Example: p.css("background- color","yellow");——Change the background color of this p to yellow. All the styles in the CSS here are exactly the same as the styles in the css style sheet without any changes
JS The method of operating styles can only obtain inline styles, not embedded or external ones! ! ! ! !
JQUERY's method of operating styles can be inline or embedded
For more programming-related knowledge, please visit:Programming video! !
The above is the detailed content of What is the difference between jquery and javascript. For more information, please follow other related articles on the PHP Chinese website!