By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,934 Members | 1,527 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,934 IT Pros & Developers. It's quick & easy.

Check if document ID exists?

P: n/a
I guess this is partly a javascript questions, but is there a way to check
if a CSS id or class exists anywhere on a page.

For example, if the id "bla" exists, it should return true only if the
following tag is on the page:

<a href="bla.html" id="bla">

Jul 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
DU
michael wrote:
I guess this is partly a javascript questions, but is there a way to check
if a CSS id or class exists anywhere on a page.

For example, if the id "bla" exists, it should return true only if the
following tag is on the page:

<a href="bla.html" id="bla">


In the above code, id is an HTML attribute name and "bla" is an HTML
attribute value.
"getElementById introduced in DOM Level 2
Returns the Element whose ID is given by elementId. If no such
element exists, returns null."
http://www.w3.org/TR/2000/REC-DOM-Le...ml#ID-getElBId

So,
if(document.getElementById("bla"))
{
... [instructions if it exists];
}
else
{
... [instructions if it does not exist];
};

DU
Jul 20 '05 #2

P: n/a
michael <no****@example.com> wrote:
I guess this is partly a javascript questions, but is there a way to check
if a CSS id or class exists anywhere on a page.
The id and class attributes are HTML element attributes, not CSS.

For example, if the id "bla" exists, it should return true only if the
following tag is on the page:

<a href="bla.html" id="bla">


if (document.getElementById("bla") == null) ...

--
Harlan Messinger
Remove the first dot from my e-mail address.
Veuillez ôter le premier point de mon adresse de courriel.
Jul 20 '05 #3

P: n/a
> if (document.getElementById("bla") == null) ...

Perfect - Thanks ! ! !

Jul 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.