Pass global value of javascript array to HTML tag

Just wondering, is it possible to pass the global value of the javascript array to the html tag, especially inside the img (title) tag?

Basically, I 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 provide other suggestions.

thank

+1
source share
3 answers

No, It is Immpossible. I suggest you set the title property using javascript. For this you need:

1) Add a JavaScript element to the element. For example, the css or id class 2) get the element through the hook and set its name

Example:

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

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

You can also use some JavaScript library like jQuery or Prototype

+2

:

<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>
+2

:

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

Source: https://habr.com/ru/post/1748337/


All Articles