Ticket #6580 (closed bug: worksforme)
Element creation and append fails.
| Reported by: | DeKay | Owned by: | |
|---|---|---|---|
| Priority: | Milestone: | 1.4.3 | |
| Component: | manipulation | Version: | 1.4.2 |
| Keywords: | dom creation class append after | Cc: | |
| Blocking: | Blocked by: |
Description
I have come across a weird behavior. I would like to output the following html:
<h5 class="toggle_div"><a href="javascript:void(0);">Text</a></h5> <div class="facets"></div> <div style="clear:both;"></div>
To do this, i thought running the following command would work:
$('<h5 class="toggle_div"></h5>').append($('<a href="javascript:void(0);"></a>').text("Text")).after('<div class="facets" id="test"></div>').after('<div style="clear:both;"></div>');
But it does not. I only get the first header (<h5> and the <a>).
However, the following works:
$('<h5></h5>').addClass('toggle_div').append($('<a href="javascript:void(0);"></a>').text("coucou")).after('<div class="facets" id="test"></div>').after('<div style="clear:both;"></div>');
All i did was set the class of the first created element AFTER its creation.
It does not seem right since i also set classes inside the other elements...
Change History
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

You were expecting the jQuery object to contain the <a> element after the append so that "Text" would be put there, but that's not how jQuery works. Folks on the forum can explain, http://forum.jquery.com .