1

Just wondering if it's possible to pass a global javascript array value into a html tag, specifically inside a img (title) tag?

Basically want to know if I can do this:

<img src="_info.gif" height="26" width="37" title=myArray[5]/>

If so, how and if not, can people possibly provide other suggestions.

Thanks

2
  • why?.. what are you trying to do? Commented Jun 2, 2010 at 8:08
  • It'd be interesting to know what this would achieve.. Commented Jun 2, 2010 at 8:14

3 Answers 3

2

No, it is not possible. I suggest that you set the title property using javascript. In order to do it you need to:

1) Add JavaScript hook to the element. For example css class or id 2) get the element via the hook and sets its title

Example:

document.getElementById("myImage").title = myArray[5];

<img id="myImage" src="_info.gif" height="26" width="37"/>

You might as well use some kind of JavaScript library, for example jQuery or Prototype

Sign up to request clarification or add additional context in comments.

Comments

2

I would do it this way:

<img id="image-1" src="_info.gif" height="26" width="37" />

<script type="text/javascript">
var image = document.getElementById('image-1');
image.setAttribute('title', myArray[5]);
</script>

Comments

1

Could also do:

<img src="_info.gif" height="26" width="37" onload="this.title = myArray[5];" />

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.