jquery - Javascript: Need to remove a single instance of a class on the page when the id is generated -
this title may little convoluted.... here goes.
i have block of code. in (i think it's called parent) span, can see id defined qa_prdcmpr_qtyspan_0. there 4 of on page (created 0-3) compare 4 products.
<span id="qa_prdcmpr_qtyspan_0" data-pa-element="compare-qty-column" name="qty-input"> <br> <input class="txtinput" type="text" name="shoppingcartqty_0" id="qa_prdcmpr_qty_0" maxlength="4" style="border:1px solid;border-color:#000 grey grey #000;width:35px"> <span width="30px" id="qa_qty_error_1375968996697" class="error">enter quantity.</span> </span> in top level span of block, in id=qa_prdcmpr_qtyspan_0. 0 generated number (there 0-3 product compare)
the long number on span id time stamp guarantee uniqueness. instead of writing page generic product container , being able include x containers on page, defined page 4 hard coded containers product comparisons. being said, can work that.
i have tried this:
/* remove error message if applicable */ var $errorelements = $('.error'); $(this).find($errorelements).remove(); i'm in process of trying this:
var errornode = $('span[id^="qa_qty_error_"]').attr('id'); while (errornode.firstchild) { errornode.removechild(errornode.firstchild); } the problem first on is removing "error" elements on page if there multiple errors. thought rid of using 'this' guess not.
do have parent / child nodes correct one?
edited clarity (an attempt)
i ended finding pc_prfix used generate 0-3 on end of id's. little deceiving of mind set of descriptive , correct variable names.
$('#qa_prdcmpr_qty_' +pc_prfix).next('span.error').remove();
Comments
Post a Comment