开发者

How to add element with old element's html and remove old element in Jquery with new?

开发者 https://www.devze.com 2023-01-25 13:38 出处:网络
I want to add new element by jquery with old element and also remove old element in place of new. For ex,

I want to add new element by jquery with old element and also remove old element in place of new.

For ex,

<div id="a1"> </div>

should be like

<table border="0" cellpadding="0" cellspacing="0">
      <tr>
       &开发者_如何学Golt;td class="Frame_Box_top_left"></td>
       <td class="Frame_Box_top"></td>
       <td class="Frame_Box_top_right"></td>
      </tr>
      <tr>
       <td class="Frame_Box_left"></td>       
       <td class="Frame_Box_inner" valign="top">

                  "new element here !"

       </td>
       <td class="Frame_Box_right"></td>
      </tr>
      <tr>
       <td class="Frame_Box_bottom_left"></td>
       <td class="Frame_Box_bottom"></td>
       <td class="Frame_Box_bottom_right"></td>
      </tr>
</table>


You can use .wrap() to put a new element around an old one, like this:

$("#a1").wrap('<div id="new" />');

For other cases not working with a single element, there's also .wrapAll(), and for wrapping contents instead of the element itself, there's .wrapInner().

0

精彩评论

暂无评论...
验证码 换一张
取 消