Home > Web Front-end > JS Tutorial > body text

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

WBOY
Release: 2016-05-16 16:46:56
Original
1272 people have browsed it

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.
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template