Tuesday, 27 December 2016

jQuery Get All Images (img) Src in Div


$('#divimages').children('img').map(function () {
return $(this).attr('src')
}).get()


<html>
<head>
<title> jQuery Get All the Images in One Div </title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script type="text/javascript">
$(function () {
$('#btnGet').click(function () {
var imgs = $('#divimages').children('img').map(function () {
return $(this).attr('src')
}).get()
alert(imgs);
})
})
</script>
</head>
<body>
<b> Get All the Images in Div </b>
<div id="divimages">
<img src="test.png" />
<img src="test2.jpg" />
</div>
<input type="button" id="btnGet" value ="Get Images" />
</body>
</html>



No comments:

Post a Comment