/    Sign up×
Community /Pin to ProfileBookmark

Working with javascript like objects

Hi all, Sorry for the… strange title but I have no other way to put it.

is it possible to handle a small section of the HTML as an Object in javascript.

For example:

[code]
/////////////////OBJECT 1///////////////////////////////
<div id=”name”></div>
<div id=”age”></div>

<script language=”javascript” type=”text/javascript”>
document.getElementById(‘name’).innerHTML = “Thijs”;
document.getElementById(‘age’).innerHTML = “20”;
</script>
/////////////////OBJECT 2///////////////////////////////
<div id=”name”></div>
<div id=”age”></div>

<script language=”javascript” type=”text/javascript”>
document.getElementById(‘name’).innerHTML = “John”;
document.getElementById(‘age’).innerHTML = “39”;
</script>
[/code]

Obviously the second Javascript will affect the first div with id ‘name’.

but for my purpose I need them to act like objects (like in PHP). Where I can set the HTML for each object seperatly.

Is this possible? Or maybe, you need me to explain some more. please reply ?

Thanks in forward

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@KDLAMay 14.2009 — Is this conditional, or do the groupings of information (name/age) always stay the same?
Copy linkTweet thisAlerts:
@TjirpauthorMay 14.2009 — They change. That's why I need to target all objects seperatly since all of their information can change at any time.
×

Success!

Help @Tjirp spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...