store information in a tag?

K

Kourosh

I want to store some state infomation for each DIV tag on a page. Which
property of the DIV tag should I use for this?
ie I want to iterate through all DIV tags, and associate each with a
'state' and store that information in the tag
 
I

Ian Collins

Kourosh said:
I want to store some state infomation for each DIV tag on a page. Which
property of the DIV tag should I use for this?
ie I want to iterate through all DIV tags, and associate each with a
'state' and store that information in the tag
Why not just add a property 'state' to each div?
 
R

Robert

Kourosh said:
I want to store some state infomation for each DIV tag on a page. Which
property of the DIV tag should I use for this?
ie I want to iterate through all DIV tags, and associate each with a
'state' and store that information in the tag

Have you thought about storing the states in a seperate javascript
object? Perhaps you can assign id's to the DIV tags that you want to
store states for and use those id's to map them to states in a seperate
object.

Robert.
 
K

Kourosh

Robert said:
Have you thought about storing the states in a seperate javascript
object? Perhaps you can assign id's to the DIV tags that you want to
store states for and use those id's to map them to states in a seperate
object.

Robert.

I see. How would i use the IDs to efficiently map to an array of
states. Is there a hashtable?
 
R

Robert

Kourosh said:
I see. How would i use the IDs to efficiently map to an array of
states. Is there a hashtable?

Each object in javascript works quite similar as a hashtable.
Take for example this code:

function StateStorage()
{
var map = new Object();

this.store = function(id, state)
{
map[id] = state;
}

this.retrieve = function(id)
{
return map[id];
}
}

var stateStorage = new StateStorage();
stateStorage.store(divId, "my state object");
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,007
Latest member
obedient dusk

Latest Threads

Top