Search code examples
jqueryinnerhtmltraversal

Using jquery to get html inside an element


I've been trying to get all the markup between li tags and move it to another div on the page. I have tried using html, innerhtml, and children. But, it just returns [object Object]...

The html (highly modified for simplicity):

<ul>
<li class="add">I want this</li>
<li class="add">I don't want this</li>
</ul>

<div id="second">
<!-- i want to insert here -->
</div>

This is the most current iteration of jQuery code...

$('li.add').click(function() {

                    var thisitem = $(this).html();
                    $("#selections").append(thisItem);
            });

Solution

  • $('li.add').click(function() {
        var thisitem = $(this).html();
        $("#second").append(thisitem);
    });
    

    Check working example at http://jsfiddle.net/wxLgH/