This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

check valid tag id  RSS feed

 
reubin haz
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd like to check if a given tag ID exists or not. I tried
typeof document.getElementById(givenID).innerHTML != "string"
or
document.getElementById(givenID).innerHTML != null

but both of them fail. Does someone know how to check if the given tag id is valid?

thanks.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if(typeof(document.getElementById("someId")) != "undefined")alert("I am here");
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!