473,385 Members | 1,875 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,385 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 11800


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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...

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.