+ 2
J.S. arrays help -
var x = [doc.get...ById("elm"), doc.get...ById("elm2")] ; x[0][1].style.display="none"; That' not working. How do you make them display none by using the x.[] ? Here's started code: https://code.sololearn.com/WB0NX5uyRS7t/?ref=app
6 Respuestas
+ 3
https://code.sololearn.com/WR8n8y2WF1Bs/?ref=app
+ 3
Your array isn't multidimensional. I get why you are confused, but getElementById doesn't return an array of elements, it only returns one, unlike getElementsByClassName or getElementsByTagName. You should just remove the last part of the array:
x[1].style.display = "none";
Side note:
You get the elements before the document is loaded, therefore it will be null. To fix this, you should wrap this code in the window.onload function. Make sure you remove the var keyword
+ 3
If you are sure that you will only have 2 elements, you can just write both lines, otherwise you should use an (enhanced) for loop
+ 2
There are 2 issues I found:
The first is that because you're loading in the JS before the HTML, there are no elements in the DOM to be manipulated, raising an error as a result of the JS not being able to find the object with the id's specified. To avoid this, you could wrap everything within:
window.onload = function(){
}
to get it to run once the HTML has loaded in.
The second issue (as Airree stated) is that you seem to be trying to find an element at an index that doesn't exist. Rather than trying to use x[0][1] to access the elements, all you would need to do is use x[i], where i is the index of the object you don't want to display (being either 1 or 0 in this case)
+ 2
ok, so i can understand what u guys are saying a little more, can you access both ids (with array x[]), and display both ' a' and ' b ' to none?
https://code.sololearn.com/WB0NX5uyRS7t/?ref=appa
Thx!
- 1
https://www.sololearn.com/discuss/1849327/?ref=app
https://www.sololearn.com/discuss/1849736/?ref=app
https://www.sololearn.com/discuss/1850249/?ref=app
https://www.sololearn.com/discuss/1847674/?ref=app
https://www.sololearn.com/discuss/1847626/?ref=app
https://www.sololearn.com/discuss/1850107/?ref=app
https://www.sololearn.com/discuss/1850037/?ref=app
https://www.sololearn.com/discuss/1850085/?ref=app
https://www.sololearn.com/discuss/1848647/?ref=app
https://www.sololearn.com/discuss/1849121/?ref=app
https://www.sololearn.com/discuss/1848275/?ref=app