Solution to grab text from page and display it elsewhere?
I am trying to find a solution how to grab a text from one part of the page to be displayed on a different part of the same page (not stored).
To explain this easier. I have this:
<div 开发者_JAVA百科id="test"> hello world </div>
I want to grab the text "hello world" and display it somewhere else on the website as well.
Im thinking that there might be a javascript code that could grab that specific div text?
Any help would be very appreciated.
var text = document.getElementById('test').innerHTML;
and to place it on some other part of the page:
<div id="otherpart"></div>
you could set the innerHTML:
document.getElementById('otherpart').innerHTML = text;
精彩评论