son Posted November 10, 2010 Share Posted November 10, 2010 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 More sharing options...
ApocalypeX Posted November 10, 2010 Share Posted November 10, 2010 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 More sharing options...
son Posted November 10, 2010 Author Share Posted November 10, 2010 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 More sharing options...
ApocalypeX Posted November 10, 2010 Share Posted November 10, 2010 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 More sharing options...
jeffman Posted November 10, 2010 Share Posted November 10, 2010 function change_image(s, w, h)Try adding a t variable to your arguments list. Link to comment Share on other sites More sharing options...
son Posted November 10, 2010 Author Share Posted November 10, 2010 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.