Jump to content

Grab and Post Image Alt Tag


Howdy_McGee

Recommended Posts

I'm trying to write a script that 'OnClick' will grab the image Alt Text and post the contents of the image alt inside a div element that is else where on the page. Much like a caption, but I'm hoping a lot simpler. I tried using the whole innerHTML thing but i'm not very familiar with javascript. Can anyone help me?

<img src="kitten.jpg" alt="This Cats Name Is Mitten!" OnClick="PostAlt()" />

Link to comment
Share on other sites

Thanks for pointing that out. The function I was thinking of would look something like this:

function PostAlt(str) {   var myDiv = document.getElementById("something");   myDiv.innerHTML = str;}

The advantage here is that the function would work with any string you passed to it, so you could have unlimited numbers of image tags all written more or less the same way, and you'd get the same results for all of them.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...