Link to home
Start Free TrialLog in
Avatar of tonelm54
tonelm54

asked on

CSS Tag

Ive got a load of divs on a page and would like to store some information on the individual divs, that I can pull in through a javascript function.

My only idea Ive got is to use the ID such as divButton_4322323_233422_31123 and then split the id using _. So if I needed to find 4322323 I could use
var parts = id.split("_") 

Open in new window

and then use
parts[1];

Open in new window


Does anyone else have any suggestion on storing information inside a div?

Thank you
Avatar of Gary
Gary
Flag of Ireland image

No, if thats all you are wanting to do though you're question isn't entirely clear...
ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If you are trying to do something like pass a variable then just use a custom attribute:

<div id="theid" custom="yourdata">

then in the script

somevar=document.getElementById('thediv').custom;

not very elegant, and not a good practice but ...

Cd&
@CD& - best to use the new html5 convention which is to prefix any custom attributes with 'data-' as per post above.

As of HTML5 it is good practice - convention was provided specifically for custom storing of data in elements to prevent having messy code as suggested by the author.
Yeah I didn't see your post or I would not have posted.  I agree data- is appropriate.

Cd&