开发者

Solution to grab text from page and display it elsewhere?

开发者 https://www.devze.com 2023-01-03 16:05 出处:网络
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).

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

精彩评论

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