Jump to content

Hover change for title and/or alt tag?


son

Recommended Posts

I have a nice script where the main image on page changes when you hover over the thumbs below. The function to change image is:

function change_image(s, w, h){  document.getElementById('rollimg').src = s;  document.getElementById('rollimg').style.width = w + "px";  document.getElementById('rollimg').style.height = h + "px";}

and the thumbs are listed as:

<span onmouseover="change_image(image0.src, 332, 500);"><img src="image0.jpg" width="66" height="100"  alt="First photo of gallery" /></span>

Can I access somehow the alt and title tag of rollimg, so I can also change the info according to relevant images? Not sure if that is possible in Javascript...Son

Link to comment
Share on other sites

alert(document.getElementById('rollimg').title)document.getElementById('rollimg').title = "Yo";alert(document.getElementById('rollimg').title)alert(document.getElementById('rollimg').alt)document.getElementById('rollimg').alt = "Alternate text FTL"alert(document.getElementById('rollimg').alt)

Link to comment
Share on other sites

alert(document.getElementById('rollimg').title)document.getElementById('rollimg').title = "Yo";alert(document.getElementById('rollimg').title)alert(document.getElementById('rollimg').alt)document.getElementById('rollimg').alt = "Alternate text FTL"alert(document.getElementById('rollimg').alt)
I changed function to:
function change_image(s, w, h){  document.getElementById('rollimg').src = s;  document.getElementById('rollimg').style.width = w + "px";  document.getElementById('rollimg').style.height = h + "px";  document.getElementById('rollimg').title = t;}

and span to

<span onmouseover="change_image(image0.src, 332, 500, 'testText');"><img src="image0.jpg" width="66" height="100" alt="First photo of gallery" /></span>

it does not work... Where am I going wrong?Son

Link to comment
Share on other sites

I changed function to:
function change_image(s, w, h){  document.getElementById('rollimg').src = s;  document.getElementById('rollimg').style.width = w + "px";  document.getElementById('rollimg').style.height = h + "px";  document.getElementById('rollimg').title = t;}

and span to

<span onmouseover="change_image(image0.src, 332, 500, 'testText');"><img src="image0.jpg" width="66" height="100" alt="First photo of gallery" /></span>

it does not work... Where am I going wrong?Son

Your image hasn't got a Title attribute, so you need to use setAttribute() instead of .title
Link to comment
Share on other sites

Try adding a t variable to your arguments list.
Adding t did the trick, cheers:-) I went now a bit further and accessed the image caption instead as:
function change_image(s, w, h, t){  document.getElementById('rollimg').src = s;  document.getElementById('rollimg').style.width = w + "px";  document.getElementById('rollimg').style.height = h + "px";  document.getElementById('imgCaption').innerHTML = t;}

I am quite pleased now...Son

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...