Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 74297

JS document.getElementById() with Int

$
0
0

I am getting some DOM elements by document.getElementById({{templete_var}}) the {{templete_var}} can be an Int. I would like to know if this can cause any errors across different browsers/devices. It works fine on Firefox (ubuntu) and Safari (Mac) but are there maybe mobile browsers where this could cause an error?

Here a little code snippet to make it clear what I mean. In the code snippet both methods work.

// 1 and 2 would be template variables here so I can't "hardcode" them
document.getElementById(1).style.color = "blue"
document.getElementById("2").style.color = "red"
<span id="1">first text</span><br><span id="2">other text</span>

Surprisingly I could not find anything on this topic, if this is a duplicate please link the original.


Viewing all articles
Browse latest Browse all 74297

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>