473,403 Members | 2,270 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Check if document ID exists?

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
3 74728
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
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
> if (document.getElementById("bla") == null) ...

Perfect - Thanks ! ! !

Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Raymond | last post by:
Hi All: To find a file exists using the file name, I have tow routings on UNIX system. 1. access(2) 2. lstat(2) This tow function also can do. When the return value is "-1" and errno is...
1
by: Pete | last post by:
Hi, i'm building a datagrid that grabs a documents location out of a database and puts them in as a hyper link column. Ideally i'd love to be able to check the validity of the link and only...
1
by: James | last post by:
vb.net 2003 i wrote a windows service that does threading. My codes are a) the service thread will read a list of machine from a text file (machines.txt). b) it then logon using the below...
3
by: samoore33 | last post by:
Is there a way to check and see if a document exists when an app loads? The first time the user starts the app, I want it to check and see if an XML document exists, which it shouldn't. Therefore...
0
by: Herb | last post by:
is there a way in an SQL stored proc to determine if a temp table exists before selecting from it....I have a java app. that is calling a stored proc. i want to check if Java created the table before...
0
by: ramith | last post by:
Guys, I wrote a simple code to check the existence of a directory (in UNIX based file systems) which is working for me. Have I done it in the correct way? #include <dirent.h>
9
reginaldmerritt
by: reginaldmerritt | last post by:
I have a table which uses two primary keys. One is a canidate code the other is a course\programme code. I have a fom with these two fields but automaticaly picks the candidates code. Therefore...
4
by: Mark Berry | last post by:
Hi, I'm working on my "last resort" error block for a web application. If the error occurs after a Request has been made, I want to show the URL. If the Request object is not available, I'll...
0
by: philip.poole | last post by:
Hi everyone, I am settings up some .NET controls on my website and want to create template controls to completely separate the business layer and the presentation layer. However I have...
2
Manikgisl
by: Manikgisl | last post by:
HI. How to check File exists in Web Share C# try { WebRequest request = HttpWebRequest.Create("http://www.microsoft.com/NonExistantFile.aspx"); request.Method = "HEAD"; // Just get...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.