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>
asked Oct 9, 2014 at 22:32
1

2 Answers 2

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/

answered Oct 9, 2014 at 22:40
Sign up to request clarification or add additional context in comments.

Comments

0

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

answered Oct 9, 2014 at 22:36

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.