JQuery - Browse <img> which are child of a specified div
i have a div, and i'll brow开发者_StackOverflow中文版se each elements child of this div.
html page :
<div class="articleviewphoto1">
<div class="articleviewphoto1small">
<a href="#" onClick="loadPhoto('53')"><img src="./articles/photos/1284393671790/1284393671790-1.jpg" class="photoartsb" id="53" /></a>
</div>
<div class="articleviewphoto1small">
<a href="#" onClick="loadPhoto('54')"><img src="./articles/photos/1284393671790/1284393671790-2.jpg" class="photoartsb" id="54" /></a>
</div>
<div class="articleviewphoto1small">
<a href="#" onClick="loadPhoto('55')"><img src="./articles/photos/1284393671790/1284393671790-3.jpg" class="photoartsb" id="55" /></a>
</div>
<div class="articleviewphoto1small">
<a href="#" onClick="loadPhoto('56')"><img src="./articles/photos/1284393671790/1284393671790-4.jpg" class="photoartsb" id="56" /></a>
</div>
</div>
(javascript page)
function loadPhoto(mexid) {
$.ajax({
type: 'POST',
cache: false,
url: './auth/ajax.php',
data: 'idp='+escape(mexid)+'&id=loadphoto',
success: function(msg) {
$('.articleviewphoto1').children('img').each(function(){
$(this).removeClass().addClass('photoarts');
});
$('#visualizator').html('somethings ('+msg+')</a>');
}
});
return false;
}
how can browse these elements? (withous using ids from tag). i know how to do it if the child are div, but with img?
cheers
As well as what Rocket says you could also use the find() method like this:
$("div.articleviewphoto1small").find("img")
$('div.articleviewphoto1small > img')
Try $('.articleviewphoto1small').children()
if there are only images in that div, or $('.articleviewphoto1small').children('img')
if there are other elements in that div too.
精彩评论