I’m trying to create a simple application – each of the three men has a rel="x" attribute attached them. I’m using var regionId = $('img.selected-region').attr('rel'); to make the rel of the currently selected item the value of reginId.
I want to test this out by performing a simple document.write(regionId) command in a div under the pictures of the men. However, it’s not working. Have I put the var regionId definition in the right place in the script window?
I’m completely new to javascript so the syntax is confusing to me – and help would be greatly appreciated.
Try this out http://www.jsfiddle.net/T6Jqx/15/
In the HTML, you have document.write in a script tag. At that time, the DOM may not be ready, but more importantly, it only executes once, not every time an image is clicked. I’ve modified it to print the “rel” attribute each time you click an image.