Jump to content

Getting Hidden Information From An Element?


rob86
 Share

Recommended Posts

I'm not sure how to explain this, but I have a <div> box but it could be an image or anything what it is isn't too important I don't think. I want to be able to store just a simple hidden numerical value in it (a rating from 1-100 for example) and then be able to extract it later for use elsewhere in the code, in a javascript tooltip for example. I haven't been able to figure out how to do this but I was reading a bit about the HTML DOM which looked like it might be useful. Any suggestions ?Another example is if I had an image of 4/5 stars, which when hovered over would be able to make a tooltip that says" The score is 4 out of 5". because the 4 was stored somehow.I'm not actually at the stage of making a tool tip or anything now, just trying to figure out how to get a number out of the object.

Link to comment
Share on other sites

You can use attributes to store information. For links, you can use rel and rev, for other elements, you can use class, though that can conflict with actually classes assigned to the object. If there aren't any existing attributes you can use, you can make one up:

elements.setAttribute('customAttribute','value');

To access information from an attribute, use getAttribute():

alert(elements.getAttribute('customAttribute'));

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...