473,398 Members | 2,343 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,398 software developers and data experts.

JavaScript "objects" to extend HTML Elements

Hi!

I create HTML pages on the server side. I want to extend DIV elements
with more information.

E.g.:

<DIV id="Joe" />

Now I want Joe to have an age for example and access it using:

$('joe').age = 20;

Doing that directly might work. Or maybe I should better use a wrapper,
which separates the person as own object from the DIV element, like:

GetPersonObject('Joe').age = 20;

I didn't use so much JavaScript until now. Maybe someone already had the
same problem and can provide or link to some code?

Regards,

Rudi
Apr 20 '07 #1
3 6141
VK
On Apr 20, 1:45 pm, Rudi Hausmann <rudi...@nospam.comwrote:
Hi!
Hi!
The German beer is the best one - I'm declaring it for each of my stay
in here but it doesn't hurt to repeat - even if out of context :-)
I create HTML pages on the server side. I want to extend DIV elements
with more information.
Cool.
E.g.:

<DIV id="Joe" />
What's this oldy yaky pseudo-XHTML stuff? Stay modern - be HTML:
<div id="joe">
Now I want Joe to have an age for example and access it using:

$('joe').age = 20;
Be aware that $ is not a native JavaScript method, it is a custom
method from prototype.js or prototype.js-compliant library. After that
you are cool again.
Doing that directly might work. Or maybe I should better use a wrapper,
which separates the person as own object from the DIV element, like:

GetPersonObject('Joe').age = 20;

I didn't use so much JavaScript until now. Maybe someone already had the
same problem and can provide or link to some code?
Well, Gecko (Firefox & Co) and IE are having a bit different opinion
on the problem. First of all, DOM Interface has nothing to do with
JavaScript object: none. Secondly, HTML source code (these text
strings sent over HTTP protocol) has a very weak relation with the
resulting DOM Interfaces client-side. They are like the pirate's code:
not a rule but merely a guideline.
I could speak for it for hours, but I'm getting my next pint Metzkater
in a few minutes, so:

<div id="foo" foobar="foo" barfoo="bar">

in this case use only $('foo').getAttribute('foobar') because of Gecko/
M$ differences.

Best!

Apr 20 '07 #2
"VK" <sc**********@yahoo.comwrote in message
news:11**********************@n59g2000hsh.googlegr oups.com...
On Apr 20, 1:45 pm, Rudi Hausmann <rudi...@nospam.comwrote:
Well, Gecko (Firefox & Co) and IE are having a bit different opinion
on the problem. First of all, DOM Interface has nothing to do with
JavaScript object: none. Secondly, HTML source code (these text
strings sent over HTTP protocol) has a very weak relation with the
resulting DOM Interfaces client-side. They are like the pirate's code:
not a rule but merely a guideline.
I could speak for it for hours, but I'm getting my next pint Metzkater
in a few minutes, so:
You could speak about quotes from "Pirates of the Caribbean" for hours?

-Lost
Apr 20 '07 #3
Hi Rudi,

On Apr 20, 2:45 am, Rudi Hausmann <rudi...@nospam.comwrote:
Hi!

I create HTML pages on the server side. I want to extend DIV elements
with more information.

E.g.:

<DIV id="Joe" />

Now I want Joe to have an age for example and access it using:

$('joe').age = 20;
I don't do this but I did see an example in a JavaScript book about
adding what they called a "backing object" to an HTML. The backing
object would have extra information and functions associated with the
object. This would be something like

$('joe').backingObject = {/*...*/};

In that book they also discussed the need to clean these backing off
the object on page unload for memory leak reasons. The problem with
this is JavaScript books are very often wrong in very substantial
ways. I did ask about this practice on comp.lang.javascript much like
you but didn't have any response.

If you do the following you do get the circular memory leak in IE
because the object the HTML object has a reference to the function and
the function has a reference to the object in it's scope chain.

var joe = $('joe');
joe.myFn = function(){};

If you do the following I am not sure if the function has the HTML
object in the function's scope chain. My guess is yes.

$('joe').myFn = function(){};

Hopefully someone else will elaborate on extending HTML objects and
the memory leak issues.

Peter

Apr 21 '07 #4

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

Similar topics

1
by: Dave C. | last post by:
Hi, I have a few things on my databases which seem to be neither true system objects or user objects - notably a table called 'dtproperties' (created by Enterprise manager as I understand,...
3
by: Lance | last post by:
I have quite an odd question. Usually I ask whenever javascript is not acting the way I'd expect. This time I'm trying to figure out why something works when I don't think it should be working! ...
6
by: kobu.selva | last post by:
I was recently part of a little debate on the issue of whether constants and string literals are considered "data objects" in C. I'm more confused now than before. I was always under the...
5
by: G. Stewart | last post by:
The word "Business" in the term implies some sort of commercial aspects or connotations. But from what I can see, that is not necesserially the case at all? So what is the reasoning behind the...
1
by: phdfromic | last post by:
I want to initialize a TEXTAREA with text depending on the values already selected in other areas - input type=TEXT or SELECT. How can I set a PHP variable with a value retrieving those HTML...
3
by: lcjohnso | last post by:
Hi all, Does anyone know if there is an easy way to create the html representation of an HTMLElement object in javascript? I'm attempting to update the innerHTML property of a div element to...
1
by: drk.kumar | last post by:
I have an implementation issue with WMI scripts to check the user machine processor. The implementation is working fine in the local machine (Windows XP operating system). It is throwing script...
14
by: Jess | last post by:
Hello, I learned that there are five kinds of static objects, namely 1. global objects 2. object defined in namespace scope 3. object declared static instead classes 4. objects declared...
2
by: PeterAlt | last post by:
Hello all! This is my first post here. I've been going crazy lately trying to master the art of working with and creating my own objects with Javascript. I see the HUGE power potential of object...
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: 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?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
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.