This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes check valid tag id Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "check valid tag id" Watch "check valid tag id" New topic

check valid tag id

reubin haz
Ranch Hand

Joined: May 12, 2005
Posts: 287
I'd like to check if a given tag ID exists or not. I tried
typeof document.getElementById(givenID).innerHTML != "string"
document.getElementById(givenID).innerHTML != null

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


Eric Pascarello

Joined: Nov 08, 2001
Posts: 15376
if(typeof(document.getElementById("someId")) != "undefined")alert("I am here");
Don't get me started about those stupid light bulbs.
subject: check valid tag id