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