Im trying to find all img
in a page and if the next tag is div.txt
add class test
on this next element.
I've tried this but I dont know why it isnt working:
for(i = 0; i < $('.page img').length; i++){
$('.page').find('img:eq('+i+')').next('.txt').addClass('teste');
}
Some help would be appreciated.
You were missing $. No need to loop, use .each() like this:
$('.page img').each(function(){
$(this).next('.txt').addClass('teste');
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.