Home >Web Front-end >JS Tutorial >Sharing the priority method of adding style attributes in jQuery

Sharing the priority method of adding style attributes in jQuery

小云云
小云云Original
2018-01-10 10:24:101307browse

This article mainly brings you a priority method for adding style attributes in jQuery (recommended). The editor thinks it is quite good, so I will share it with you now and give it as a reference for everyone. Let’s follow the editor to take a look, I hope it can help everyone.

Add multiple attributes to the jQuery class

$('#five .a')
.css({
  color:'blue',
  border:'2px solid green',
  background:'blue'
});

jQuer adds classes to elements

$('#five .a')
.addClass('funny');

HTML code

 <style>
.funny{
  font-size: 21px;
  background-color: gray ;
  padding: 10px;
  color: yellow ;
}
 </style>
<p id="five">
  <p class="a">A</p>
</p>

You can see that the rendering effect of adding multiple attributes to the jQuery class appears as an inline style.

The class added by jQuer to the element does not have a high priority as the inline style.

You can see that there are no funny background-color: gray; and color: yellow; attributes in the rendering effect.

Related recommendations;

Summary of examples of methods for obtaining various CSS style attributes in native javascript

jQuery Add priority level of style attributes

HTML Basics (5)-css style sheet style attribute format and layout

The above is the detailed content of Sharing the priority method of adding style attributes in jQuery. 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