1

Is there any tool / library which would:

  1. Take HTML markup as input
  2. Auto-generate a jQuery script which, in return, if executed, would
  3. Generate the original HTML?
3
  • 2
    Nothing personal, but... You're doing something wrong if you need such thing. It depends on how complex your HTML is. If there's something pretty simple, then $('<div class="content">...</div>') will do. Commented Dec 3, 2014 at 18:30
  • 1
    If it is a little more complex, $.parseHTML(...) should help you as well. api.jquery.com/jquery.parsehtml Commented Dec 3, 2014 at 18:31
  • @AndrewDunai, works perfectly in my case, thanks! You may also add your comment as an answer, I'll accept it (maybe just add a reference to the official doc). Commented Dec 3, 2014 at 18:36

1 Answer 1

1

As I wrote in comment, It depends on how complex your HTML is.

If there's something pretty simple, then

$('<div class="content">...</div>')

will return your HTML as DOM element already wrapped in jQuery. Otherwise (if you have scripts, events etc) you'll need to use $.parseHTML (as mentioned by @emergence) and pass extra arguments.

Here's official doc for .parseHTML: http://api.jquery.com/jquery.parsehtml/

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.