Note that there are some explanatory texts on larger screens.

plurals
  1. POjquery .replaceWith() not playing nice with .clone() in IE7
    primarykey
    data
    text
    <p>I'm using jQuery to created a linked TOC that appears in a dialog box. The function I wrote to do so finds all the <code>h4</code>'s in the page and</p> <ul> <li>gives them <code>id</code>s to link to </li> <li>adds some numbering display info </li> <li>clones them</li> <li>turns the clones into <code>li</code>s </li> <li>wraps the inner text in anchor tags </li> <li>finds the anchors adds a click function to the anchors to close the dialog</li> <li>adds <code>title</code>s and <code>href</code>s to the anchors so the links point to the original <code>h4</code>s</li> <li>goes back to the <code>li</code>s </li> <li>appends the <code>li</code>s to a <code>ol</code> the in dialog <code>div</code></li> </ul> <p>However, in <strong>IE7</strong>, the cloned <code>h4</code>s are not getting turned in <code>li</code>s. Works in FireFox. In IE7, everything happens as it does in FireFox, just that the the <code>.replaceWith()</code> is seemingly ignore... why?</p> <p>Looks like this:</p> <pre><code>$('#content h4').each(function(index) { index = index + 1; $(this) .attr('id', 'tutorial_' + index) .before(function() { return '&lt;div class="how_to"&gt;HOW TO&lt;div&gt;&lt;span&gt;' + index + '&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;'; }) .clone() .replaceWith("&lt;li&gt;" + $(this).text() + "&lt;/li&gt;") .wrapInner("&lt;a&gt;&lt;/a&gt;") .find('a') .click(function(){ $("#dialog").dialog("close"); }) .attr({ 'title': 'jump to ' + $(this).text(), 'href': '#tutorial_' + index }) .end() .appendTo('#dialog ol') }); </code></pre> <p>In action at: <a href="http://f1shw1ck.com/jquery_sandbox/tutorials.html" rel="nofollow noreferrer">http://f1shw1ck.com/jquery_sandbox/tutorials.html</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload