Modifying the TR class appears to be ineffective in this instance

I am attempting to update the TR className using JavaScript. However, for some reason it does not appear to be working properly (please note that it must also work in IE8).

<html>
<head>
  <style>
    tr.test {background-color:#000000;margin:0;border:0;padding:0;}
  </style>
  <script>
  _table = document.getElementsByTagName("table")[0];
  _tbody = _table.getElementsByTagName("tbody")[0];
  _tr = _tbody.getElementsByTagName("tr")[0];
  _tr.className="test";
  </script>
</head>
<table>
  <tbody>
    <tr>
    <td></td>
    </tr>    
  </tbody>

</table>
</html>

Answer №1

Insert your code below the table element

<html>
<head>
  <style>
    tr.example {background-color:#000000;margin:0;border:0;padding:0;}
  </style>
</head>
<body>
<table>
  <tbody>
    <tr>
    <td></td>
    </tr>    
  </tbody>

</table>
<script>
  _table = document.getElementsByTagName("table")[0];
  _tbody = _table.getElementsByTagName("tbody")[0];
  _tr = _tbody.getElementsByTagName("tr")[0];
  _tr.className="example";
</script>
</body>
</html>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The static page is missing the favicon icon

For the past four days, I've been diving into the world of HTML and CSS to create my own personal webpage. As a beginner, I haven't yet hosted it and am still in the process of crafting it. One thing I attempted was designing a favicon for my sit ...

The Bootstrap button is experiencing difficulties with resizing

When utilizing the bootstrap CDN in conjunction with another bootstrap CSS example file located in the static directory, I encountered an issue while attempting to create a file input and submit button for a form. Despite my efforts, I was unable to adjust ...

CSS - Mysterious Gaps Found in Div Block

Below is the code snippet I am currently working with: html { height: 100%; overflow: hidden; } body { height: 100%; color: #bdc3c7; font-family: Montserrat; background-color: #3E4651; } .nav { ...

Accessing specific documents in Firebase cloud functions using a wildcard notation

Currently, I am working on implementing Firebase cloud functions and here are the tasks I need to achieve: Monitoring changes in documents within the 'public_posts' collection. Determining if a change involves switching the value of the &ap ...

Slide one div up when another div is hovered over

I have a block named case-card with a child division called case-card__wrapper that contains text. When hovering over the case-card, I would like the case-card__wrapper to subtly move upwards in a transition, rather than abruptly jumping from one position ...

Utilize Javascript to acquire the redirected URL

Seeking assistance with making a GET call to an API endpoint that redirects me. I have enabled CORS to access the Location, but struggling to find a way through Ajax or Fetch to retrieve only the Redirect URL. Any help would be highly appreciated. ...

Tips for limiting the size of image uploads to under 2 megabytes

I am trying to implement an html select feature that allows users to upload images. <div class="row smallMargin"> <div class="col-sm-6"> Attach Image </div> <div class="col-sm-6"> <input type="file" ng-model="image" accept=" ...

What is the best way to combine text with a PayPal field variable?

We recently encountered an issue with our standard PayPal Form implementation for online payments. Our form includes a field for customers to input a pickup date/time, using the passthrough variable "invoice" as recommended in the PayPal Docs. Everything w ...

How to Sort JSON Data Based on Property in JavaScript

I've got a serialized JSON collection: [ { "_id":"person1", "date":"7/20/2014 17:20:09", "listed_name":"Tom", "name":"Tom", "contact_info":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data ...

Ways to clear all CSS rules from a class without deleting the class itself using jQuery

Clear out all CSS properties within a class without actually removing the class itself using jQuery For instance : .ui-widget { font-family: Verdana, Arial, sans-serif/*{ffDefault}*/; font-size: 1.1em/*{fsDefault}*/; left: 350 ...

Template for Vue.js Component Registration

Below is a simple Vue component example: const MyComponent = Vue.component('my-component', { data () { // data here... }, methods: { // methods here... }, template: '<p>Hello, world !!!</p>' }); I ...

What does the error "Cannot access property 'length' of null when using 'angular'" mean?

I am currently working on counting the initial li items and encountering an issue with 'Cannot read property 'length' of null' after fetching data from the server using a unit test case. Here is my code: import { ComponentFixture, Tes ...

Synchronization-free API and callback functions

I am in need of utilizing an asynchronous service. My current approach involves sending data to this service using PHP and CURL, as well as receiving data from a URL provided by the service. How can I effectively respond or wait for feedback from this serv ...

Ways to eliminate the gap preceding <br> code

My footer contains two sections: one for the address and one for contact information. The address section is styled using <p> tags with <br/> elements inside, while the contact information section is styled using <span> elements with a di ...

Why isn't my jQuery code functioning properly on Weebly?

Hello, I'm a beginner in coding and have very limited skills in this area. However, I am able to install scripts on my Weebly site and have been doing so for some time now. Even though I can't code, I've managed to learn a few things along t ...

Having trouble with the click button flip function? It seems to be working in one section but not in

Currently, I am facing an issue with a card section that contains two buttons and a description. The first button adds an image which is working perfectly fine, as well as the description section. On the other hand, the second button adds a video and when ...

The problem arises when using `$state.go` as it does not properly transfer the value to `$stateParams`

Within componentA, I am using an angular code: $state.go('home', {selectedFilter: "no_filter"}); In componentB, I have the following code: if ($stateParams.selectedFilter === 'no_filter') However, I am encountering an issue where $s ...

Struggling to input data into Excel using Selenium WebDriver

I encountered an issue while attempting to write two strings to an Excel sheet using the following code. The error message I received was: java.lang.IllegalArgumentException: Sheet index (0) is out of range (no sheets) FileOutputStream fout=new FileOutput ...

Example using Three.js Collada: "file is either empty or does not exist"

I am currently troubleshooting the Three.js Collada loader example. I have successfully run other samples, including the .obj loader and blender scene, by running a local http server to load images for textures and models. However, when attempting to run t ...

Ways to incorporate text into a div container

For my assignment, I am working on setting up a menu website and I want to create a floating side div for the order summary. If you need a visual reference, you can check out this Figma design: Just to clarify, this is my first time dealing with coding s ...