This book is badly out of date and will probably never be updated. You can find more up-to-date information on the Greasemonkey wiki.

Dive Into Greasemonkey

Teaching an old web new tricks

4.3. Testing whether a page includes an HTML element

You can use the getElementsByTagName function to test whether an HTML element exists on a page.

Example: Check if the page contains a <textarea>

var textareas = document.getElementsByTagName('textarea');
if (textareas.length) {
    // there is at least one textarea on this page
} else {
    // there are no textareas on this page
}

Real examples

← Testing whether a Greasemonkey function is available
Doing something for every HTML element →