views:

43

answers:

1

I have a script that runs within the body. How can I make it output directly after itself. Similar to echo in php.

e.g.

    <div id="text">Text</div>

    <div id="someotherdiv">
    The text above says 
    <script>
    $('#text').html().echo?;
    </script>
    </div>
+7  A: 

You're looking for document.write, like this:

document.write($('#text').html());

EDIT: document.write will only work while the page is loading (as opposed to in an event handler or timer).
To append content later, use jQuery:

$('#someotherdiv').append($('#text').html());
SLaks
I tried this and it replaced the entire page. I want it to output next to the </script> tag... please help
Pablo
This will only work while the page is still loading. If not, you should use jQuery's `after` (or similar) method to insert the element or HTML into the DOM.
SLaks