Reputation: 21
I try to get src or id of image in datalist using javascript. Here is some of the code:
<script type="text/javascript">
$(document).ready(function () {
$('.productImage').mouseover(function () {
var imageUrl = $('.productImage').attr('src');
//alert(imageUrl);
$.ajax({
type: "POST",
url: "WebServiceVar.asmx/getVarImage",
contentType: "application/json; charset=utf-8",
dataType: "json",
data: "{'imageUrl':'" + imageUrl + "'}",
success: function (data) {
}
})
});
});
</script>
When hovering over any image in datalist the alert(imageUrl) method displays only "images/products/image1.png", although there are multiple images in the DataList.
Upvotes: 0
Views: 159
Reputation: 305
You need to add below code this is helpful for you.
var imageUrl = $(this).attr('src');
If your mouseover event call with any image hover then current image src you have get using 'this' above code line.
Upvotes: 1