Reputation: 3503
I have a div
block that is repeated on the page for each product. I am using JS to cycle through all the instances of a div
class and would like to move that div
to another div
in the same block. I wrote this:
$(value).appendTo('.product-image')
and it adds each div
to all the product-image
divs on the page. How can I add each div
only to the product-image
div
that is a child of $(values)
parent?
This did not work for me:
$(value).appendTo($(value).parent().find('.product-image'))
Upvotes: 1
Views: 97
Reputation: 3503
i came up with this sulotion thanks !
ind++
var tryy = "try"+ind;
$(value).parent().find('.product-image').addClass(tryy);
var tryyy = '.'+tryy;
$(value).appendTo(tryyy);
Upvotes: 1
Reputation: 1504
I think this will give you some ideas for implementation:
For example if you value
element has value
class:
$('.value:has(.product-image)').find('.product-image').each(function(){
$(this).append(your_new_div)
});
Upvotes: 1
Reputation: 461
Try this to select the first parent div.
$(value).appendTo($(value).parent('div:first()').find('.product-image'))
Upvotes: 1