Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to identify the objects in page in a function?Is there a ID?

Status
Not open for further replies.

Wangfeel

Technical User
May 7, 2003
5
CN
I only can use "this " to identify the picture object, how to identify picture by other means except "this", then maybe I can deal with their alpha value in a function without the input variant "this"?

-<-@ W.H @->-
 
You can access all elements on a page in a number of ways. For example an image defined like so:
Code:
<img src=&quot;my.gif&quot; id=&quot;mypic&quot; name=&quot;mypic&quot;>
could be referred to as:
Code:
document.all.mypic
document.getElementById('mypic')
document.images[0] (assuming it is the first image)
 
dwarf,

document.all only works with Internet Explorer. I'm convinced you don't want people to be locked out if they aren't rich enough to buy Windows so I recommend document.all never be used at all.

Wangfeel,

document.getElementById is the DOM1 standard compliant way of getting any item with an ID attribute.

As dwarfThrower states you can also use the document.images[] collection. There are two ways you can use it :

document.images[0] // where 0 means it is the first image 1 the second etc...

and

document.images[&quot;myPic&quot;] // where myPic is the name attribute of the image.

Using document.all will only work with Internet Explorer. I'm using Mozilla Firebird right now on a linux system (I do not have Windows). Please don't lock me out of your site!! :)


Gary Haran
==========================
 
It's a bad habit of mine. I build intranet applications for large corporates and government departments. I have the luxury of dictating the code dictate the operating environment rather than the other way around.
 
I had this kind of problem with <A href....> tags and found documnet.links[x].onmouseover/onmouseout/href and .length work a treat in NS 4.5 & IE5.0 - according to &quot;SAMS publishing&quot; book &quot;Pure Java&quot; (a good reference tome) it will work on NS2+ IE3+ Opera3+ (or something similar) and I put the solution in a thread yesterday.

I struggled with documaent.all.bytagRef (or similar) and several permutations on a theme without success.

The book is not that expensive 25 GBP (say $35 US). AND if I was working I would consider it pocket money.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top