A user specifies a numerical value; then a for loop runs it that many times. I have a series of these types of set ups, and they all work, except this one. I believe it’s because of the :first selector I’ve used.
jQuery.fn.removeX = function() {
for (var i = 0; i < xTimes; i++) {
$("#Tell").append(' removed!');
$("#List_" + C_user + " img:first").relocate();
}
}
I’ve tried variations, such as :nth-child(0), even .slice(), but so far nothing works. However, the .relocate function, it’s designed only to handle one element at a time. I didn’t think should make a difference, but if I switch it out for something like .appendTo, it works fine.
The .relocate script:
jQuery.fn.relocate = function(){
getSRC2 = $(this).find('img').attr('src');
$(this).prependTo(".List_" + Owner).removeAttr('style');
$(this).remove();
}
It’s nothing special, so I’m not sure how it breaks the other one.
Any tips/pointers would be helpful.
SOLUTION
Removed the .find(), worked, thanks! I was trying to reuse the script, but the objects it was originally designed for are wrapped, hence the .find().
Here, you’re selecting an
img…Then in
.relocate(), you’re doing a.find()on theimg…An
imgcan’t be nested inside animg.Either get rid of the
.find('img')since you already have it, or get rid of theimgpart of the selector…