Home >Web Front-end >JS Tutorial >What is the difference between jquery attr and css

What is the difference between jquery attr and css

coldplay.xixi
coldplay.xixiOriginal
2020-11-18 15:54:012682browse

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.

What is the difference between jquery attr and css

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:What is npm in reactNext article:What is npm in react