Hi,
I have an Image Control (asp Control) that want get value of it’s ImageUrl attribute in javaScript code.
how to do this?
Thanks for your attention.
You could use Javascript’s
document.getElementById() function to target your appropriate Image element (using it’s
ClientID property) and then accessing the ‘src’ attribute :
<!-- Example Image --> <asp:Image ID="YourImage" runat="server" ImageUrl="..." /> <!-- Example Script to retrieve the URL --> <script type='text/javascript'> // Resolve the appropriate client-side ID for your Image and then grab the source for the Image (src) var url = document.getElementById('<%= YourImage.ClientID %>').src; // Alert or do something with the URL here alert(url); </script>
javascript:
var srcImg= document.getElementById(‘<id of image>’).getAttribute("src");
using jquery:
var srcImg = $(‘#<id of image>’).attr(‘src’);