The difference between JQ and JS memo

Source: Internet
Author: User

From JS to JQ, thought it was easy to master. But still found a lot of problems, the big God in the group often said that JQ is just a library, to simplify the operation of the DOM, and is not omnipotent. So there are some ways to be aware of it.

1.var $li =$ (' Li ') is not dynamically acquired element, distinguished from native JS

2.attr and CSS Differences
CSS is set style, equivalent to style.display=block; same effect

3. Change the class style
With attr, you cannot add CSS styles
CSS is the style that changes styles, attr is the property of modifying HTML

<!doctype html>. item{width:100px;height:100px;background:red;}. Active{width:100px;height:100px;background:yellow;} </style><script src= "Http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js" ></script><script >$ (function  () {    var $div =$ ("#div1");    $ ("#btn1"). Click (function() {        $div. attr (' class ', ' active ');    }) </script>

But it doesn't work with CSS.

<!doctype html>. item{width:100px;height:100px;background:red;}. Active{width:100px;height:100px;background:yellow;} </style><script src= "Http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js" ></script><script >$ (function  () {    var $div =$ ("#div1");    $ ("#btn1"). Click (function() {        $div. css (' class ', ' active ');//Change to CSS    });}) </script>


4. Photo Wall (one of the exercises)
Oneself not equal to oneself

The difference between JQ and JS memo

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.