Check if DIV ID or CLASS exists

C

Charlie C.

What is the simplest code of finding out if a certain div (with a
name) exists in a html or flash?
 
T

Thomas 'PointedEars' Lahn

Charlie said:
Subject: Check if DIV ID or CLASS exists

What is the simplest code of finding out if a certain div (with a
name) exists in a html or flash?

Names are not IDs. The latter must be unique in a document, the former does
not need to:

http://www.w3.org/TR/html401/struct/global.html#h-7.5.2

if (document.getElementById("divID"))
{
// ...
}

http://www.w3.org/TR/DOM-Level-3-Core/core.html#ID-getElBId

if (document.getElementsByName("divName").length > 0)
{
// ...
}

http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-71555259

The usual feature tests should be applied at run time:

http://www.jibbering.com/faq/faq_notes/not_browser_detect.html


Determining whether or not an element with a specific `class' attribute
value exists is more complicated as there is no DOM interface method for
that. However, you can use HTMLDocument::getElementsByTagName("*") and
filter the returned NodeList, or you can use XPath:

http://www.w3.org/TR/DOM-Level-3-Core/core.html#ID-A6C9094
http://developer.mozilla.org/en/docs/XPath

I wonder why you would deem it necessary to find that out.


For Flash scripting, try macromedia.flash.actionscript instead. Although
ActionScript is an ECMAScript implementation, too, chances of a helpful
answer are better in the newsgroup dealing solely with that particular
implementation and the DOM it operates on. Especially since Flash is a
proprietary media format that is generally frowned upon because of its
not allowing full accessibility, much in contrast to HTML.


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,156
Messages
2,570,878
Members
47,404
Latest member
PerryRutt

Latest Threads

Top