troubleshooting Question

jQuery getElementsByTagName not working

Avatar of pzozulka
pzozulka asked on
1 Comment1 Solution3977 ViewsLast Modified:
I'm doing an assignment for a class, where it says I need to modify jquery.altrow.js to create a plugin that uses the getElementsByTagName method to get all of an element’s “tr” child elements. They provide the following HTML and JavaScript:
<!DOCTYPE html>
    <meta charset="UTF-8">	
    <title>Alternating Row Plugin</title>
    <link rel="stylesheet" href="altrow.css">
    <script src=""></script>
    <script src="jquery.altrow.js"></script>
    <script src="altrow.js"></script>
      <h1>Important People in Computer Science</h1>
      <table id="important">
                <th>First Name</th><th>Last Name</th><th>Date of Birth</th><th>Accomplishment</th>
                <td>Originated the concept of a programmable computer, invented the first mechanical computer.</td>
                <td>First computer programmer. Wrote an algorithm for Babbage's mechanical computer.</td>
                <td>Invented the Turing Machine, a hypothetical device that's a model of a general purpose computer.</td>
                <td>Invented the first compiler for a computer programming language, popularized the term "debugging" for fixing computer glitches.</td>
"use strict";

window.onload = function() {
    $( document ).ready(function() {
"use strict";

	$.fn.highlightRows = function() {
		var testItems = this.getElementsByTagName("tr");

I am getting an error in Chrome's F12 tools console:

Uncaught TypeError: this.getElementsByTagName is not a function

I tried using the jQuery find method instead which works fine, but the question here is to use getElementsByTagName instead.
Join our community to see this answer!
Unlock 1 Answer and 1 Comment.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 1 Comment.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros