output with javascript/jquery
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>
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());
精彩评论