document.getElementById not working even if I ve ID present in my css

前端 未结 2 1466
粉色の甜心
粉色の甜心 2020-12-20 08:20

I tried searching but didnt get a valid answer to my question. I always get \"null\" when I call document.getElementById(\"#\"+id) and it alerts Document

相关标签:
2条回答
  • 2020-12-20 08:44

    document.getElementById() does not need the pound (#) symbol.

    0 讨论(0)
  • 2020-12-20 08:46

    While you're using JavaScript, you don't use # sign to reference the ID of the element.

    Your code for

    alert("#"+id);
    

    Would be

    alert(id);
    

    You need # Number sign, only when working with CSS or jQuery.

    0 讨论(0)
提交回复
热议问题