开发者

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;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜