+ 1

I have problems with javascript span

I have just been in the lesson changing objects in DOM AND EVENTS and the truth was I did not understand well how to use span in the last question, can you explain how that modification is used? I was testing and I do not identify how

17th Jul 2020, 10:33 PM
Armando Zuñiga
Armando Zuñiga - avatar
4 Respostas
+ 1
That should be id="zero" and also there is no tag name by id zero ,tag name should be span in this case,if you remove that h1 tag around text,it will work fine,due to some properties of h1 ,span element hides behind it ,and somehow I did found it but I Don't really understand how these block or nested inline elements work inside each other ,maybe that's a topic you can consider going through or think about it ,I haven't yet so can't help further , hopefully someone else can explain you much better
17th Jul 2020, 11:32 PM
Abhay
Abhay - avatar
+ 2
thanks, you helped me a lot by the way the h1 probe tags and you can put the span tag inside the h1 tag, I repeat, thank you very much
18th Jul 2020, 12:11 AM
Armando Zuñiga
Armando Zuñiga - avatar
+ 1
It selects all elements with tag span var s=document.getElementsByTagName("span"); Now s is a nodelist of all span elements So you need to iterate through it like you would do for normal array and change its background color using style.backgroundColor for(let i=0;i<data.length;i++){ s[i].style.backgroundColor="red"; }
17th Jul 2020, 10:49 PM
Abhay
Abhay - avatar
0
I already tried, but I can't add it to a real situation: HTML: <!DOCTYPE html> <html> <head> <title>hola</title> </head> <body> <div id="hello" style="width: 200px"> <span id = zero style ="width: 200px"> <h1> hola que tal </h1> </span> </div> <script type="text/javascript" src="ultitled.js"> </script> </body> </html> archive JS(name: ultitled.js): var s = document.getElementsByTagName("zero"); for(var x = 0; x < s.length; x++){ s[x].style.backgroundColor = "red"; } where does it go?
17th Jul 2020, 11:11 PM
Armando Zuñiga
Armando Zuñiga - avatar