Check out example codes for "html change attribute". It will help you in understanding the concepts better.

Code Example 1

element.setAttribute(name, value);


var d = document.getElementById("d1"); 
d.setAttribute("align", "center");

Code Example 2

element.setAttribute(<name>, <value>);
// ex
var aElement = document.querySelector("a"); 
aElement.setAttribute("href", "https://isitchristmas.com/"); 
// same as <a href="https://isitchristmas.com/"></a>

Learn ReactJs, React Native from akashmittal.com