This is Interesting: Free Magazines for Graphics designers and webmasters  


Home > Archive > Stylesheets > June 2004 > Check if document ID exists?





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Check if document ID exists?
michael

2004-06-23, 4:15 am

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">

DU

2004-06-23, 4:15 am

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-L...tml#ID-getElBId

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

DU
Harlan Messinger

2004-06-23, 12:19 pm

michael <nomail@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.
michael

2004-06-23, 12:19 pm

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

Perfect - Thanks ! ! !

Sponsored Links


Copyright 2003 - 2008 forum4designers.com  Software forum  Computer Hardware reviews