0

This will output [object HTMLUListElement]:

ul = document.create('ul');
$('textarea').val(ul)

How do I get it to output <ul></ul>?

This will do the work but is there any way to get it directly from the html element object?

s = ul.wrap('<div></div>')
$('textarea').val(s.html())
1
  • Seems a rather round about way to get the markup, given that you already know the tag name of the element. Commented May 20, 2015 at 2:59

1 Answer 1

3

Use outerHTML property of the element

ul = document.createElement('ul');
$('textarea').val(ul.outerHTML)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<textarea></textarea>

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

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.