Clear text but keep image inside <a> hyperlinks using jQuery -
how can remove "product x" , keep images using jquery?
<span class="product-field-display"> <a href="/products/product-a-detail" original-title="product a"> <img alt="product-a" src="/images/resized/product_a_180x180.png">product a</a> </span> <span class="product-field-display"> <a href="/products/product-b-detail" original-title="product b"> <img alt="product-b" src="/images/resized/product_b_180x180.png">product b</a> </span>
i tried with:
$j('span.product-field-display a').html('');
and with:
$j('span.product-field-display a').text('');
but gets cleared , not text
you can grab image, clear out anchor, , put image back:
$j('#gkcomponent .productdetails-view .product-related-products .product-field-type-r span.product-field-display a').each(function() { var $this = $(this); var img = $this.find('img').detach(); $this.empty().append(img); });
or removing text nodes anchor via dom, leaving img
element intact:
$j('#gkcomponent .productdetails-view .product-related-products .product-field-type-r span.product-field-display a').each(function() { var node, nextnode; node = this.firstchild; while (node) { nextnode = node.nextsibling; if (node.nodetype === 3) { // 3 = text node node.parentnode.removechild(node); } node = nextnode; } });
Comments
Post a Comment