0

I have

<img alt="text" src="source" />

I'd like to get this alt to one var in JavaScript. It'll be better if it won't be necessary to use jQuery.

Please for help :)

2

2 Answers 2

0

You could do like this:

document.getElementById('imgId').getAttribute('alt')
Sign up to request clarification or add additional context in comments.

Comments

0

can get any attribute by .getAttribute

i.e.

imgAlt.getAttribute("alt")

imgAlt.getAttribute("title")

const imgAlt = document.getElementById("myImg");

console.log(imgAlt.getAttribute("alt"));
<img id="myImg" alt="text" src="source" />

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.