0

I am trying to define some basic HTML:

<ul id="menu" style="display:none">
    <li><a class="actions" href="1">1</a></li>
    <li><a class="actions" href="2">2</a></li>
    <li><a class="actions" href="3">3</a></li>
</ul>

And append it dynamically using jquery like so:

$('#container').append($('#menu')).show()

However all that's returned is the physical Object:

<div id="container">[object Object]</div>

Can my menu div be appended in this fashion?

UPDATE: Revised where the show() is placed, but outcome remains the same

3
  • 4
    jsfiddle.net/tbk2cLfL Works to me.... Commented Jul 13, 2015 at 18:44
  • If you can, post your actual code (pastebin.org if needed) so that I can see what's going on, but it seems weird. Commented Jul 13, 2015 at 19:08
  • Make sure to have your js code after the html, or use $(document).ready() Commented Jul 13, 2015 at 19:11

3 Answers 3

1

While this might work, I would probably run .show() AFTER you append the items to the page. The .append does not expect a function, it's just expecting a DOM element, which may be the cause of your problems.

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

Comments

1

This works for me (tried with jQuery 1.6 -> 2.1.3) Did you use a simplified code example in your question? I suspect you are using a string concatenation somewhere like in this thread: Jquery returns [object object] when trying to manipulate dom

2 Comments

Yes I did include a simplified code sample. I'll update my question
Still cannot reproduce (it appends content but the content does not get shown, so output is empty). You should try to create a JsFiddle where you reproduce your issue consistently, then share it here so we can help you.
0

This way it should work:

$('#container').append( $('#menu').show() );

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.