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_3 1123 and then split the id using _. So if I needed to find 4322323 I could use
Does anyone else have any suggestion on storing information inside a div?
Thank you
My only idea Ive got is to use the ID such as divButton_4322323_233422_3
var parts = id.split("_")
and then use
parts[1];
Does anyone else have any suggestion on storing information inside a div?
Thank you
No, if thats all you are wanting to do though you're question isn't entirely clear...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.getElemen tById('the div').cust om;
not very elegant, and not a good practice but ...
Cd&
<div id="theid" custom="yourdata">
then in the script
somevar=document.getElemen
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.
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&
Cd&