473,387 Members | 1,590 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,387 software developers and data experts.

Add a property to an HTML element

Hi,
Is there any way of adding a property to an HTML element ?
I heard about the "prototype" method but it doesn't work for HTML elements
such as Images, or Paragraphs...
Netscape implements HTMLElement objects but it seems to me that no
equivalent exists in Internet Explorer ?? (I hate that browser :)
Any idea ?

Thank you, John.
Jul 20 '05 #1
3 11801


jonjon wrote:
Hi,
Is there any way of adding a property to an HTML element ?
I heard about the "prototype" method but it doesn't work for HTML elements
such as Images, or Paragraphs...
Netscape implements HTMLElement objects but it seems to me that no
equivalent exists in Internet Explorer ?? (I hate that browser :)
Any idea ?


You can add a property to any object, simply by using
object.property = ...
If your aim is to add a property to a "class" of objects, that is to
objects sharing a prototype object, then indeed only Mozilla exposes
such prototypes for objects in the DOM.

--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #2
"jonjon" <j.********@wanadoo.fr> writes:
Is there any way of adding a property to an HTML element ?
Adding a property to one HTML element is simple. Just add it
elem.property = "foo";
I heard about the "prototype" method but it doesn't work for HTML elements
such as Images, or Paragraphs...
All Javascript objects have an internal link to a prototype object,
where properties are looked up if they haven't been set on the object
itself. There doesn't have to be a way to access the prototype object,
though. For arrays and objects, you can get to it as Array.prototype
and Object.prototype. There is no similar constructor for DOM HTML
elements.

(Actually, in Mozilla, the constructors Image and Option have
prototype properties, in IE they don't).
Netscape implements HTMLElement objects but it seems to me that no
equivalent exists in Internet Explorer ?? (I hate that browser :)
Any idea ?


I would add the property manually to all the elements I interact with.

I usually have a function that uses getElementById or document.all to
access an element. I add other properties there too if I need them.
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #3
"Lasse Reichstein Nielsen" <lr*@hotpop.com> a écrit dans le message de
news:y8**********@hotpop.com...
"jonjon" <j.********@wanadoo.fr> writes:
Is there any way of adding a property to an HTML element ?


Adding a property to one HTML element is simple. Just add it
elem.property = "foo";
I heard about the "prototype" method but it doesn't work for HTML elements such as Images, or Paragraphs...


All Javascript objects have an internal link to a prototype object,
where properties are looked up if they haven't been set on the object
itself. There doesn't have to be a way to access the prototype object,
though. For arrays and objects, you can get to it as Array.prototype
and Object.prototype. There is no similar constructor for DOM HTML
elements.

(Actually, in Mozilla, the constructors Image and Option have
prototype properties, in IE they don't).
Netscape implements HTMLElement objects but it seems to me that no
equivalent exists in Internet Explorer ?? (I hate that browser :)
Any idea ?


I would add the property manually to all the elements I interact with.

I usually have a function that uses getElementById or document.all to
access an element. I add other properties there too if I need them.
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'

Thanks very much for the clarification Martin and Lasse, that really helped
me a lot.

Best regards,

John.
Jul 20 '05 #4

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

Similar topics

3
by: Robert Mark Bram | last post by:
Howdy all! When do I call something a property and when do I call something an attribute? It has me a little confused at the moment! Any advice would be most appreciated! Rob
4
by: Neil Zanella | last post by:
Hello, Consider the height property in the code shown below... I am dissatisfied with the height propery. When I set it to 100% the table does not fill the entire vertical space available to...
5
by: Secret Guy | last post by:
Because of my experience posting various places over the last couple of weeks: I'm expecting to be greated with hostility for asking about concepts instead of "practical" things, since that has...
6
by: Java script Dude | last post by:
We just discovered another IE bug. When an html form contains an element with a name of `name` IE's internal index screws up the .name property of the containing form to point to the bad element...
3
by: joealey2003 | last post by:
Hi all... I included a css file on my html and i need to check some properties. The html is: <style id="myid" src="mycsspage.css"> </style> Now i need something to access it like: ...
1
by: prasaddevivara | last post by:
I am using the outerHTML property to modify the HTML of existin elements in a web page in Internet Explorer. But same outerHTM property is not working in firefox browser, Anybody can tell me a...
13
by: Robert Bravery | last post by:
HI all, I created a property callsed closed with in a select tag for each option. The property is then assigned a value of 0 or 1. I then evaluate this property in a JS script When I do this...
5
by: turnitup | last post by:
Hi, I need to access the innerHTML property of a div using the dot notation, eg document.body.div, rather than the GetElementbyID. So far I have not found the correct way to do it. I would be...
2
by: funktacular | last post by:
Hi - I have some javascript that works when I run it from a server, but I need to run it locally. When I try to execute it locally I get the following error: Error: uncaught exception: Permission...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.