Home  >  Article  >  Web Front-end  >  jQuery gets/sets/delete attributes of DOM elements, taking the a element as an example_jquery

jQuery gets/sets/delete attributes of DOM elements, taking the a element as an example_jquery

WBOY
WBOYOriginal
2016-05-16 16:46:561231browse

jQuery's attribute operations are very simple. The following uses an a element to illustrate the attribute acquisition/setting/deletion operations

Copy code The code is as follows :

Add attributes

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

Add multiple attributes

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

Get attributes

$('a' ).attr('href')

class attribute

addClass()

Add a class

hasClass()

Judge Whether there is a class specified in the parameter

removeClass()

Remove a class

toggleClass()

If the class specified in the parameter already exists, If it is deleted, otherwise it will be added.
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