Попытка использовать .replaceWith () для замены <div> - PullRequest
0 голосов
/ 20 января 2011

Здравствуйте, я новичок здесь и не увидел ничего похожего на мой вопрос.Это может показаться простым, но, похоже, не работает.Я пытаюсь заменить div с id = 'CAShip' другим html.

Вот код.JQuery:

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

Это начальный HTML:

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

Это HTML, который я хочу заменить на:

<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>

Есть предложения?

1 Ответ

2 голосов
/ 20 января 2011

Вам нужно обернуть ваш код в обработчик ready:

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