Jump to content

Show selected div inside another div


sali1101

Recommended Posts

I am trying to create a cart system using jquery. I want to show the div called "product" inside the div called "cart" if the checkbox inside the .product is selected. But bear inmind that only the div.product inwhich the checkbox is checked should be shown in .cart not all the divs called .product.  

I tired using the jquery append function but i moves all the .product divs to the cart even if 1 of them is selected. 

My html is as follows : 

 

<div class="product-list"> 
<div class=" product Earrings "> 
   <div class=" product-info"> 
     <input type="checkbox" name=" E45" value="1000"> 
     <div class=" product-name "> Product 1  </div> 
     <div class="product-price"> Rs 1500 </div> 
   </div> 
</div>

 <div class=" product Earrings "> 
   <div class=" product-info"> 
     <input type="checkbox" name=" E46" value="1000"> 
     <div class=" product-name "> Product 2 </div> 
     <div class="product-price"> Rs 1300 </div> 
   </div> 
</div>
  
</div>

<div class="cart">
  Show products in here ... 
</div>

 

Edited by sali1101
Link to comment
Share on other sites

Did you on clicking of checkbox, and that it was checked, transverse up to its parent container '.product' and append that only!

You need to target the a check box within '.product' class with click event $(this) will now represent that specific clicked checkbox. You then target that specific checkboxes parent elements

$(this).parents()

will target the parent and there parent container elements, to make it to a specific parent add that class name, to give you

$(this).parents('.product')

This is the parent element you need to append, by simple using '.products' to append, that's not specific, so all elements with class name 'products' will be appended.

Edited by dsonesuk
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...