You are here: Home → Table of contents → Common Patterns → Testing whether a page includes an HTML element
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
}