When you create a HTML element and add an ID to it, like:
<div id="test"></div>
It will be automatically available in Javascript as the variable test
without the need to use document.getElementById("test")
.
What I want to know is what happens when you create an ID with dashes, like:
<div id="test-one"></div>
This element will still be available in Javascript through some variable or the variable won't be created? I tried to check the value of test-one
and testOne
but none of them contains something.
EDIT
I think most of people are misunderstanding the question. I know that creating a variable with dashes is perfect valid.
This is the problem: http://jsfiddle.net/jn33bgkd/
You don't need to use document.getElementById
because Javascript creates global variables automatically with the same names of the IDs (i know it's a bad practice to use those, I just wanna know what's the behavior)
But these global variables aren't created if the ID has a dash. The question is if the global variable of the element that has an ID with dash is really not created or is created with a differente name.