0

I've been trying for days to figure this out and need some help.

On my site, every users shopping cart will have different items in it, but if a specific item is in the cart i want to the "Remove Item" button to be copied to an additional location.

<!-- Here's how Business Catalyst outputs the buttons -->    
<div class="cart-item product-remove" style="border:solid 1px black;" >
  <div class="productitemcell"><a href="#" onclick="UpdateItemQuantity(0,324897,282161,9383682,336573,'','US');return false;">Remove Item</a></div>
  <div class="productitemcell"><a href="#" onclick="UpdateItemQuantity(0,324897,282161,9383705,336574,'','US');return false;">Remove Item</a></div>
  <!--the div below contains the button (anchor tag) I want to copy (It will move around the .product-remove div)-->
  <div class="productitemcell"><a href="#" onclick="UpdateItemQuantity(0,324897,282161,9383678,336585,'','US');return false;">Remove Item</a></div>
</div>    

<div id="sendLinkHere" style="border: 1px solid blue; width: 100%; height:50px;">
  <!-- I want the a tag containing "9383678" copied here -->
</div>    

Here's the javascript I have. I know it's not a lot but it's all i've got.

var divsOfA = document.getElementsByClassName("productitemcell");

console.log($.inArray("9383678",divsOfA));

2 Answers2

0

Here's one way to do it. Not the best way I'm sure.

var divsOfA = $(".productitemcell a");

$.each(divsOfA, function (i, obj) {

  var onclickVal = $(obj).attr('onclick');
  
  if ( onclickVal.indexOf('9383678') > 0 ) {
    
    var $parentCellClone = $(this).parent().clone();
    
    $('#sendLinkHere').append($parentCellClone);
  }
  
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div class="cart-item product-remove" style="border:solid 1px black;" >
  <div class="productitemcell"><a href="#" onclick="UpdateItemQuantity(0,324897,282161,9383682,336573,'','US');return false;">Remove Item</a></div>
  <div class="productitemcell"><a href="#" onclick="UpdateItemQuantity(0,324897,282161,9383705,336574,'','US');return false;">Remove Item</a></div>
  <!--the div below contains the button (anchor tag) I want to copy (It will move around the .product-remove div)-->
  <div class="productitemcell"><a href="#" onclick="UpdateItemQuantity(0,324897,282161,9383678,336585,'','US');return false;">Remove Item</a></div>
</div>    

<div id="sendLinkHere" style="border: 1px solid blue; width: 100%; height:50px;">
  <!-- I want the a tag containing "9383678" copied here -->
</div>    
elzi
  • 5,442
  • 7
  • 37
  • 61
0
$(function() {
    copy(9383678);
})

function copy(num)
{
    $('.productitemcell').each(function(){
        var $a=$(this).find('a');
        var str=$a.attr('onclick');
        if(str.indexOf(num)>-1)
        {
            $('#sendLinkHere').append($a)
        }

    })
}
dm4web
  • 4,642
  • 1
  • 14
  • 20