0

this should be a pretty straightforward question. My app is built on Ruby on Rails (I doubt that this is very important though -- I'm noting this so you all understand the syntax below)

I have these two div:

<div id = "1"><%= user.Name %></div>
<div id = "2">Placeholder</div>

When someone mouses over div with id 1, I would like to replace the content of the div with id 2.

The catch is that the content I want to replace div 2 with is contained in the user object. So ideally, I'd like to set some kind of additional tag on the div that I can lookup on the JavaScript mouseover. Otherwise, I'll have to do an AJAX call that will result in a DB query to pull the relevant data.

I have no idea what that tag would be ... any hints on what I could do?

Thanks! Ringo

Ringo Blancke
  • 2,444
  • 6
  • 30
  • 54
  • You could use `data-` attributes I guess. – elclanrs Feb 07 '13 at 23:30
  • but those are HTML5 only, right? What % of browsers support HTML5? – Ringo Blancke Feb 07 '13 at 23:30
  • It's a matter of searching http://stackoverflow.com/questions/2412947/do-html5-custom-data-attributes-work-in-ie-6 – elclanrs Feb 07 '13 at 23:35
  • @RingoBlancke: Also see http://stackoverflow.com/questions/3957867/is-there-any-problem-with-using-html5s-data-attributes-for-older-browsers – Matt Feb 07 '13 at 23:54
  • As stated in the latter question, the browsers don't need to "support" this. Browsers have always just left tags and attributes that they don't recognize alone. As long as they can be set and retrieved with `setAttribute` and `getAttribute`, everything is fine. – Barmar Feb 07 '13 at 23:58
  • awesome thanks folks. I didn't know about the caniuse website that NeS specified, I think I'm good to go with this info!! – Ringo Blancke Feb 08 '13 at 00:25

1 Answers1

0

if possible, you can use the html5 'data-*' atribute to store whatever you want for further manipulation. learn more about this atribute | browser compatibility

Sergiu
  • 311
  • 4
  • 15