Home >Web Front-end >JS Tutorial >What is the difference between js and jquery
The difference between js and jquery: 1. js is a web script language, while jquery is a front-end framework encapsulated based on js language; 2. jquery objects have more "$()" than js objects; 3. The keyword for operating styles in js is style, and the keyword for operating styles in jquery is css.
The difference between JavaScript and jQuery:
1. Essential difference:
js is a web script language, and jQuery is a front-end framework encapsulated based on js language. In other words, js is a language, and jQuery is a framework based on this language. [Recommended reading: JavaScript Tutorial]
2. Differences in usage:
In appearance, there are more jQuery objects than js objects "$( )", this is the most intuitive difference;
Operation content
Non-form elements (if it is text, use the text method, if it is html code, use the html method ):
For example:
div.text();——If there is no parameter, the value is
div.text("aaaa");——Yes In the case of parameters, the value is assigned
div.html(); - In the case of no parameters, the value is
div.html ("aaaa"); - In the case of parameters Is assignment
Form element:
JavaScript:div.value;——Value;div.value = xxx;——Assignment;
jQuery:div.val( );——Without parameters, it is a value, and with parameters, it is an assignment.
Operation attributes
Methods used to operate attributes in JavaScript:
div.setAttribute("","");——Set attributes , modify the attribute
div.removeAttribute("");——Remove the attribute, write an attribute name in the quotation marks
div.getAttribute();——Get the attribute
Methods used to operate attributes in jQuery:
Add attributes: div.attr ("test", "aa"); ——Add parameters to this attr method, the attribute name is test, and the attribute value is aa
Remove attributes: div.removeAttr("test"); ——Remove the attribute test
Get attributes: div.attr("test"); ——In attr Just write the name of an attribute directly into the method
Operation style
The keyword for operating style in JavaScript is style
Example: div .style.backgroundColor = "red";——Set the background color of this div to red
The keyword for operating styles in jQuery is css
Example: div.css ("background-color", "yellow"); - Change the background color of this div to yellow. All the styles in the CSS here are exactly the same as the styles in the css style sheet without any changes. .
#The JavaScript method of operating styles can only get inline styles, not embedded or external ones.
jQuery's method of operating styles can be inline or embedded.
The above is the detailed content of What is the difference between js and jquery. For more information, please follow other related articles on the PHP Chinese website!