Rohan Khajuria
Rohan Khajuria

Reputation: 726

Get All Text Elements from Page

I am working on a Chrome extension that finds top few font sizes on a page. In order to do so, I need to get all of the text related elements from the page. How can I pull any text related element from the HTML page using JavaScript?

Upvotes: 0

Views: 613

Answers (1)

Basit
Basit

Reputation: 1840

Fairly simple. Use the following code.

textInputs = [];
var fields = document.getElementsByTagName("input"),
_length = fields.length,
input;
for(var i = 0; i < _length; i++){
    input = fields[i];
    if (!input.type || input.type === 'text'){
            textInputs.push(input);
    }
}

Upvotes: 1

Related Questions