Thursday, October 5, 2023
 Popular · Latest · Hot · Upcoming
142
rated 0 times [  145] [ 3]  / answers: 1 / hits: 62634  / 15 Years ago, thu, april 16, 2009, 12:00:00

Given a section of HTML, can I selectively pick some types of elements (e.g., input) and add a custom attribute using JavaScript? I would also need to remove this attribute if it exists.


I have done this before using jQuery, but I'm unable to use it for this particular task.


More From » javascript

 Answers
19

Accessing HTML attributes using the DOM



element.hasAttribute('foo');
element.getAttribute('foo');
element.setAttribute('foo', value);
element.removeAttribute('foo');

[#99694] Friday, April 10, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ethanc

Total Points: 57
Total Questions: 111
Total Answers: 111

Location: Vanuatu
Member since Fri, May 13, 2022
1 Year ago
ethanc questions
Thu, Jan 28, 21, 00:00, 3 Years ago
Fri, Dec 11, 20, 00:00, 3 Years ago
Mon, Jul 13, 20, 00:00, 3 Years ago
Tue, May 12, 20, 00:00, 3 Years ago
;