Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>IE6/7 has a lot of <a href="http://google.com/search?q=createelement+ie" rel="nofollow noreferrer">problems/bugs/misbehaviours</a> with regard to creating and adding elements in the DOM using <code>createElement</code>. I strongly recommend to switch to <a href="http://jquery.com" rel="nofollow noreferrer">jQuery</a> for this since it does all the work in a cross browser compatible manner and has already taken (almost) all the IE6/7 specific misbehaviours into account so that you don't need to end up with a doubled amount of code to get it to work in all browsers the world is aware of. Here's a copy'n'paste'n'runnable <a href="http://sscce.org" rel="nofollow noreferrer">SSCCE</a>:</p> <pre><code>&lt;!doctype html&gt; &lt;html lang="en"&gt; &lt;head&gt; &lt;title&gt;Test&lt;/title&gt; &lt;script src="http://code.jquery.com/jquery-latest.min.js"&gt;&lt;/script&gt; &lt;script&gt; $(document).ready(function() { $('#add').click(function() { var newElement = $('&lt;div class="filter"&gt;&lt;a href="#" class="delete"&gt;delete&lt;/a&gt;&lt;/div&gt;'); $('#container').append(newElement); }); }); &lt;/script&gt; &lt;style&gt; .filter { background: pink; } .delete { background: yellow; } &lt;/style&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="container"&gt;&lt;/div&gt; &lt;button id="add"&gt;add&lt;/button&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p><strong>Update</strong>: as per the comments, jQuery is absolutely not an option. Well, best what you can try is to set element attributes only <em>after</em> the element is been added to the DOM. Also try not to clone nodes in IE6/7, this is often epic fail. Rather create a brand new node from beginning on.</p>
 

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