JQuery gets and sets and removes the attributes of DOM elements take element a as an example

  • 2020-03-30 03:03:23
  • OfStack

JQuery's properties operation is very simple, the following is an a element to illustrate the properties of the get/set/delete operation
 
<body> 
<a>jquery.com</a> 
</body> 

Add attributes

$(' a '). Attr (' href ', 'http://www.jquery.com')

Add multiple attributes

$(' a '). Attr ({' href ':' http://www.jquery.com ', 'the title: "jquery.com"})

Retrieve attributes

$(' a '). Attr () 'href'

The class attribute

The addClass ()

Add a class

HasClass ()

Determines whether there is a class specified in the argument

RemoveClass ()

Remove a class

ToggleClass ()

If the class specified in the argument already exists, delete it, and if not, add it.

Related articles: