i tried changing html tag content but it not working
document.getElementsByTagName('h4').innerHTML('Hi world');
h4{
color:red;
}
<h4>Hello world</h4>
i tried changing html tag content but it not working
document.getElementsByTagName('h4').innerHTML('Hi world');
h4{
color:red;
}
<h4>Hello world</h4>
You're just using the innerHTML property the wrong way.
The right method is .innerHTML = 'Hi world';
Read more about innerHTML here: https://www.w3schools.com/jsref/prop_html_innerhtml.asp
Also, don't forget to select the first index of the array as the getElementsByTagName
function returns an array of elements
document.getElementsByTagName('h4')[0]
document.getElementsByTagName('h4')[0].innerHTML='Hi world';
h4{
color:red;
}
<h4>Hello world</h4>
It says "getElements" so it's PLURAL. It's a collection of elements so you need to specify which to operate on and hence the square brackets...
document.getElementsByTagName('h4')[0].innerHTML='Hi world';
document.getElementsByTagName('h4')[0].innerHTML = 'Hi world';
h4{
color:red;
}
<h4>Hello world</h4>