开发者

Trying to use .replaceWith() to replace a <div>

开发者 https://www.devze.com 2023-02-05 14:23 出处:网络
Hello I am new here and didn\'t see anything quite like my question. It may sound simple but it doesn\'t seem to work. I am trying to replace a div with id=\'CAShip\' with some other html.

Hello I am new here and didn't see anything quite like my question. It may sound simple but it doesn't seem to work. I am trying to replace a div with id='CAShip' with some other html.

Here is the code. The jquery:

<script type="text/javascr开发者_如何学编程ipt">
$('#CAShip').click(function(){
    $('#CAShip').replaceWith('New HTML code');
});
</script>

This is the starting html:

<div id="CAShip">
<table class="contentpaneopen">
  <tr>
    <td class="contentheading" width="100%">Canadian Customers Click Here Before Ordering!
    </td>
  </tr>
</table>
</div>

This is the HTML I want to replace it with:

<div>
<table class="contentpaneopen">
  <tr>
    <td class="contentheading" width="100%">Attention Canadian Customers!
    </td>
  </tr>
</table>

<table class="contentpaneopen">
  <tr>
    <td valign="top" >
    <span class="body">Please note that there are fees associated with shipping to Canada from the US that are <b><u><i><font color="red">NOT</font></i></u></b> included in the cost of the shipping or the cost of the unit. These cost are to be paid for by the purchaser. Here are some tips for shipping to Canada:
    <br />
    <br />
    -USPS methods are cheap but very unreliable. <b>Border fees</b> are not charged using USPS, only UPS or Fed Ex (which are the most reliable).
    <br />
    -<b>Customs fees</b> can sometime run <b>up to 50%</b> of the purchase price (UPS/FedEx).
    <br />
    -Smart Strips are available from a Canadian dealer. Visit our <a href="index.php?Itemid=146" title="Store Locator" target="_blank">Store Locator</a> to find a local seller.
    <br />
    -Customers with a UPS or FedEx account may ship on their account and assume all fees with no delays.
    <br />
    -Canadian customers selecting UPS or FedEx will have to pick the package up at their local station and pay the fees. So you order it online, but still have to drive and pay to pick it up unless you used your own UPS/Fed Ex account.</span>
    </td>
  </tr>
</table>
</div>

Any suggestions?


You need to wrap your code in ready handler:

<script type="text/javascript">
$(function(){
  $('#CAShip').click(function(){
    $('#CAShip').replaceWith('New HTML code');
  });
});
</script>
0

精彩评论

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