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

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -