0

I have this html code:

<html>
  <head>
    ... // call jquery etc // 
    <script src="dialog.js"></script>
    ...
    <script type="text/javascript">
      openmydialog(); // open dialog defined with jquery in dialog.js //
    </script>
  </head>   
  <body>
    ...
    <div id="my-div"> Text </div>
    ...
  </body>
</html>

well, all work correctly. I have only a problem. How I can export the:

<div id="my-div"> Text </div>

in dialog.js and to do that work correctly? I have tried defining a variable, writing something like:

var myvar = '<div id="my-div"> Text </div>';
$("#my-div").html(myvar);

but did not worked. I have tried too with document.write but same. Any solution for it?

1 Answer 1

1

You were close, if you're starting with HTML...

var myvar = '<div id="my-div"> Text </div>';

...you need to parse it and then add it to the page somewhere

    $(myvar).appendTo(document.body);
//  ^^^^^^^^ ^^^^^^^^ ^^^^^^^^^^^^^
//  Parse it   add it   somewhere

appendTo is just one of the many ways you can add it to the page; more on that (and jQuery in general, including how you parse snippets of HTML) in the documentation.

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.