Sunday, 15 March 2015

javascript - Print value of array item containing specific number in a substring -



javascript - Print value of array item containing specific number in a substring -

i've been trying days figure out , need help.

on site, every users shopping cart have different items in it, if specific item in cart want "remove item" button copied additional location.

<!-- here's how business catalyst outputs 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 button (anchor tag) want re-create (it move around .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;"> <!-- want tag containing "9383678" copied here --> </div>

here's javascript have. know it's not lot it's i've got.

var divsofa = document.getelementsbyclassname("productitemcell"); console.log($.inarray("9383678",divsofa));

here's 1 way it. not best way i'm sure.

class="snippet-code-js lang-js prettyprint-override">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); } }); class="snippet-code-html lang-html prettyprint-override"><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 button (anchor tag) want re-create (it move around .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;"> <!-- want tag containing "9383678" copied here --> </div>

javascript arrays shopping-cart business-catalyst

No comments:

Post a Comment