Jump to content

Grab and Post Image Alt Tag


Howdy_McGee
 Share

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...