2010-04-29 16 views
5

agradecería un poco de ayuda con base a una condición, le gustaría reemplazar el siguiente bloque de html:Cómo sustituir un bloque de HTML con otro bloque de código HTML con jQuery

<table class="t12PageBody" cellpadding="0" cellspacing="0" width="100%" summary=""> 
    <tr><td colspan="2">#REGION_POSITION_01#</td></tr> 
</table> 

<table width="100%" summary=""> 
<tr> 
    <td class="t12ContentBody" valign="top"> #SUCCESS_MESSAGE# #NOTIFICATION_MESSAGE# #BOX_BODY# #REGION_POSITION_04##REGION_POSITION_05##REGION_POSITION_06##REGION_POSITION_07##REGION_POSITION_08#</td> 
    <td align="right" valign="top" class="t12ContentBody">#REGION_POSITION_03#<br /></td> 
</tr> 
</table> 

con este bloque:

<div id = "banner"> 
<div class="Logo"></div> 
<img src="http://www.abc.com/home/images/spacer.gif" height="35" width="180" border="0" alt=""> <font class="bannertext">&APPNAME.</font> 
<div class="bannerText"> 
    <div class="hmenu"><ul>&APPLICATION_LINKS.</ul></div> 
</div> 

miré a la función de reemplazar en jQuery, pero sin saber cómo aplicar.

Gracias.

Respuesta

13
var newHTML = '<div id = "banner"><div class="Logo"></div>' + 
       '<img src="http://www.abc.com/home/images/spacer.gif" ' + 
       'height="35" width="180" border="0" alt=""> <font ' + 
       'class="bannertext">&APPNAME.</font><div class="bannerText">' + 
       '<div class="hmenu"><ul>&APPLICATION_LINKS.</ul>' + 
       '</div></div>'; 
$('table.t12PageBody').replaceWith(newHTML); 
+0

@Matthew ¿sería posible volver a formatear su entrada? romper las líneas o algo para que sea más legible? – BerggreenDK

+0

@BerggreenDK Lo he dividido en múltiples cadenas concatenadas. –

+0

Gracias Matthew y a todos los que respondieron, todo bien. – tonyf

0

Si usted tiene un contenedor para la que desea ponerlo, utilice .html(...)

$('#wrapper').html('<div id = "banner">' + ...); 
+1

Es más fácil sólo para usar la función 'replaceWith' en este caso. –

Cuestiones relacionadas