2

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);
            });

2 Answers 2

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

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

Sign up to request clarification or add additional context in comments.

Comments

1

you can try this also.. but dont forget to include jquery library.

<script>
 $(document).ready(function(){

var tr3 = $(".add li").eq(1).html();
var tr4 = $(".add li").eq(2).html();

$("#second ").html('<ul>'+ tr3 +'</ul><ul>'+ tr4 +'</ul>');

$(".add li").eq(1).hide();
$(".add li").eq(2).hide();

});
</script>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.