View Single Post
Old 12-02-2012, 12:04 AM   PM User | #24
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
Still not sure where the descriptions are coming from?? Are they stored in, and retrieved from, a database?

Anyway, although I mentioned title, I would generally prefer not to use it. You can use 'data-*' HTML5 attributes which are supported by the jQuery data() method.

Code:
<img id="thisone" src="whatever.gif" data-desc="Here be a description." height="100" width="100">

alert($('#thisone').data('desc'));
If you are using JS to create data-* attributes (after the page has loaded) then you need to use setAttribute(), or attr() in jQuery.

FWIW If you are running JS/jQuery code after the page has loaded you can just invent your own properties and attach them to DOM elements:

Code:
var myImage = document.getElementById("thisone");
// jQuery: var myImage = $('#thisone');
myImage.anyPropertyIFancy = "Ta Da!";
These properties can then be read directly by your code, but this is probably not relevant to your current code.
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS

Last edited by AndrewGSW; 12-02-2012 at 12:06 AM..
AndrewGSW is offline   Reply With Quote