2012-11-12 3 views
1

Je dois ajouter des tags d'image personnalisés à des champs Meta WP eCommerce mais quand je l'ajoute, il tire comme texte. Je voudrais donc utiliser Jquery pour trouver et remplacer les parenthèses < afin qu'elles soient affichées en tant que balises à la place.Trouver < à <en utilisant jQuery

Voici mon code source:

<div class="custom_meta"> 
<strong>CODE: </strong>JL16<br> 
<strong>Colour: </strong>&lt;img src="http://localhost:81/live_products/shop/wp-content/uploads/blue.gif" /&gt;<br> 
<strong>COLOURS: </strong>BLACK, WHITE, GREY, CORAL, BLUE<br> 
<strong>FABRIC: </strong>LYCRA<br> 
</div> 

Voilà comment je pense qu'il devrait travailler dans jQuery:

jQuery(document).ready(function(){ 

    // Remove "" from meta image 
    jQuery(".custom_meta").replace(/&lt;/g, '<'); 
    jQuery(".custom_meta").replace(/&gt;/g, '>'); 

}); 

Serait-ce la bonne façon de remplacer le &lt;-< et le &gt; à > ?

Merci.

+1

Juste un conseil: 'jQuery (function ($) {/ * utiliser maintenant librement $ * /});' –

Répondre

1

Cela devrait le faire

jQuery(".product_description").html(function(i, currenthtml){ 
    return currenthtml.replace(/&lt;/g, '<').replace(/&gt;/g, '>'); 
}); 

En savoir plus au documentation about .html()

+0

Merci Gaby ! Cela a fait l'affaire! – SixfootJames

Questions connexes