0

I am trying to update the DOM with some HTML and scripts that use jQuery. The section of the DOM that is being updated is BEFORE the jQuery code is called (within the DOM), but since the jQuery is what places this code the code is placed after the jQuery is called.

Can this work? I cannot get it to right now.

Here's my HTML:

<div id="readThisData">
    Some data
</div>
<div id="addScript">
    No script yet
</div>

<script src="http://code.jquery.com/jquery-2.1.0.min.js"></script>

<script>
    $( document ).ready(function() {
        $('#addScript').html(console.log($('#readThisData').html()));
    }
</script>
Justin Elkow
  • 2,833
  • 6
  • 28
  • 60
  • 1
    http://stackoverflow.com/questions/3857874/how-to-dynamically-insert-a-script-tag-via-jquery-after-page-load -- been discussed before. – Christopher Robot Oct 09 '14 at 22:36

2 Answers2

1

First of all, console.log() display things on the console, it does not run code. Second, jQuery has a very nice method to run scripts more info here : http://api.jquery.com/jquery.getscript/

GramThanos
  • 3,572
  • 1
  • 22
  • 34
0

It's just because console.log return undefined, try this: $('#addScript').html($('#readThisData').html());

Fathy
  • 4,939
  • 1
  • 23
  • 25