Is it possible to programmatically select any text on a web page in the <p> tag or the <span> tag?

Is it possible to programmatically select any text on a web page in a tag or tag

? an input element and a textarea element can do this easily, but what about text in other cases?

+3
source share
2 answers

You can find an example of getting inner text from a tag <p> here . Same thing with <span>.

To set it, you just need to set the InnerText property.

javascript ( ..), GetElementById <p> <span> - - , .

+1

JohnIdol , Firefox. . innerText. , textContent, FF.

getElementById , , , , <p> <span>. , , <p> , , :

var p = document.getElementsByTagName('p')[3];
var text = p.innerText || p.textContent;
0

Source: https://habr.com/ru/post/1708577/


All Articles