Can we modify the attribute's value of the HTML tag dynamically? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 8

Can we modify the attribute's value of the HTML tag dynamically?

13th Sep 2019, 8:45 AM
★彡 Unoosha_17 彡★
★彡 Unoosha_17 彡★ - avatar
5 Answers
+ 7
Yes of course You can modify it by using JavaScript Here is the syntax document.getElementByTagName("tag name").setAttribute("attribute name", "value");
14th Sep 2019, 1:59 PM
Ayushi Gujarati
Ayushi Gujarati - avatar
+ 5
Yes, with JavaScript: document.getElementsByTagName("H1")[0].setAttribute("class", "democlass");
13th Sep 2019, 9:12 AM
Dejan Dozet
Dejan Dozet - avatar
+ 2
Hi, can you elaborate on your idea further in detail? I suppose there will be more people interested with detailed explanation. Write some more in the Description section so your idea could be more comprehensible. Good luck with solution 👍
13th Sep 2019, 8:58 AM
Ipang
+ 1
Yes! Whith JavaScript language.
13th Sep 2019, 8:56 AM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 1
Also you can do it with JQuery: $("#myCheckBox").attr("checked", true); or $("#myCheckBox").prop("checked", true); or $("#myDiv").attr("title", "this is my hint...");
18th Sep 2019, 8:43 PM
Catalin Popinciuc
Catalin Popinciuc - avatar