Home >Web Front-end >JS Tutorial >What is the difference between jquery attr and css
The difference between jquery attr and css: 1. Attr obtains and modifies the attributes of the element, such as the src attribute and alt attribute of img; 2. CSS obtains and modifies the attributes in the style, that is, attributes in style.
The difference between jquery attr and css:
The difference between attr and css
attr(): What is obtained and modified is the attribute of the element, such as the src attribute and alt attribute of img, the href attribute of a link, etc.
css(): What is obtained and modified is the attributes in the style, that is, the attributes in the style.
$("#test").css("display", "block");//第1种方法
$("#test").attr("style", "display:block;");//第2种方法
$("#test").show();//第3种方法
Be careful not to write
$("#test").attr("display", "block");
Related free learning recommendations: JavaScript (video)
The above is the detailed content of What is the difference between jquery attr and css. For more information, please follow other related articles on the PHP Chinese website!