Categories
JavaScript Answers

How to get the image src value with jQuery and JavaScript?

Spread the love

Sometimes, we want to get the image src value with jQuery and JavaScript.

In this article, we’ll look at how to get the image src value with jQuery and JavaScript.

How to get the image src value with jQuery and JavaScript

To format a number to get the image src value with jQuery and JavaScript, we can use the prop method.

For instance, if we have the following img element:

<img src='https://i.picsum.photos/id/96/200/300.jpg?hmac=q257RPq4_aD8wno1Mkb4eP37WQzxDcNNLPu_HBwKdag'>

Then we can get the src attribute value with

console.log($('img').prop('src'))

Therefore, the console log logs 'https://i.picsum.photos/id/96/200/300.jpg?hmac=q257RPq4_aD8wno1Mkb4eP37WQzxDcNNLPu_HBwKdag'.

Conclusion

To format a number to get the image src value with jQuery and JavaScript, we can use the prop method.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *