3

I have piece of offline html like so:

<img src="../img/button.png"/>

and when I try to access the src attribute in JS, I get a different value than what's written in the html:

var s = myimg.src; // equals 'file:///V:/test/test1/img/button.png'

It's as if the value got resolved somewhere between the html and my call to 'src' attribute. How do I get the "original" value instead of the resolved one?

tnx

2 Answers 2

6

use getAttribute

var s = myimg.getAttribute('src')
Sign up to request clarification or add additional context in comments.

Comments

2

If you read the attribute instead of the src property, you get the original value:

var s = myimg.getAttribute('src');

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.