Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding alt attribute to image in javascript

I want to know how to add alt attribute to an image in javascript, below is my code...

var image = document.createElement('img');
image.src='../../KY/images/common/buttons/browseIcon.png';

Thanks in advance.

like image 879
mukund Avatar asked Mar 18 '13 07:03

mukund


2 Answers

You have two ways : you can use either alt property

image.alt = "Your text here"

or setAttribute method

image.setAttribute("alt","Your text here");
like image 103
Bigood Avatar answered Sep 28 '22 06:09

Bigood


Above mentioned methods would not work when u create buttons or any other element in dom javascript, and for this use the below mentioned method

control.setAttribute("title","your tooltip value")
like image 21
umar Avatar answered Sep 28 '22 06:09

umar