What could be the reason for my table row not showing up after clicking the button?

Having trouble with a new drop-down row in a form. The drop-down is only showing in the first cell, even when using colspan=5.

Is there a better way to achieve this? Thank you for any help.

<table cellspacing=0 cellpadding=7 border=1>
  <tr bgcolor=#efefef>
    <td></td>
    <td>Date</td>
    <td>DATA</td>
    <td>MORE DATA</td>
    <td>Method</td>
  </tr>
  <tr>
    <td>
      <button onclick="javascript:showElement('abcdata')" style="padding:4px" class=verd8> SHOW NEW ROW </button>
    </td>
    <td>Jan 22, 2022</td>
    <td>SOME DATA</td>
    <td>SOME MORE</td>
    <td>BUTTONDROP</td>
  </tr>
  <tr id="abcdata" style="display:none;">
    <td colspan=5>
      SHOW NEW ROW ACROSS ALL CELLS : sfdgsdfgs hlahhfa la dfl dfljhsd flhsd flhsdf lhdsfh asf alhd a</td>
  </tr>

  <tr>
  <td colspan=5>
  ADDED THIS tr/td IN EDIT : NOTHING HIDDEN.... DOES IT SHOW ALL ACROSS?? YES IT DOES
  </td>
  </tr>

</table>

Answer №1

Hey there! I'm not sure where you found the showElement function, but to make your row visible again, a simple way is to use abcdata.style.display=''

<button onclick="abcdata.style.display=''"

<table cellspacing=0 cellpadding=7 border=1>
  <tr bgcolor=#efefef>
    <td></td>
    <td>Date</td>
    <td>DATA</td>
    <td>MORE DATA</td>
    <td>Method</td>
  </tr>
  <tr>
    <td>
      <button onclick="abcdata.style.display=''" style="padding:4px" class=verd8> SHOW NEW ROW </button>
    </td>
    <td>Jan 22, 2022</td>
    <td>SOME DATA</td>
    <td>SOME MORE</td>
    <td>BUTTONDROP</td>
  </tr>
  <tr id="abcdata" style="display:none;">
    <td colspan=5>
      SHOW NEW ROW ACROSS ALL CELLS : sfdgsdfgs hlahhfa la dfl dfljhsd flhsd flhsdf lhdsfh asf alhd a</td>
  </tr>
</table>

Answer №2

function revealElement(id) {
  document.getElementById(id).classList.remove('hidden');
}
.hidden {
  display: none;
}
<table cellspacing=0 cellpadding=7 border=1>
  <tr bgcolor=#efefef>
    <td></td>
    <td>Date</td>
    <td>DATA</td>
    <td>MORE DATA</td>
    <td>Method</td>
  </tr>
  <tr>
    <td>
      <button onclick="javascript:revealElement('abcdata')" style="padding:4px" class=verd8> SHOW NEW ROW </button>
    </td>
    <td>Jan 22, 2022</td>
    <td>SOME DATA</td>
    <td>SOME MORE</td>
    <td>BUTTONDROP</td>
  </tr>
  <tr id="abcdata" class="hidden" >
    <td colspan=5>
      SHOW NEW ROW ACROSS ALL CELLS : sfdgsdfgs hlahhfa la dfl dfljhsd flhsd flhsdf lhdsfh asf alhd a</td>
  </tr>
</table>

I don't see your code but I assume you are using display: block to show the td.

My suggestion is to create a css class named hidden.

Apply it to the element you wish to hide.

To reveal the element, simply remove the class.

P.S. I advise against modifying specific properties with JS unless absolutely necessary.

Answer №3

It appears that there is a misunderstanding about the showElement() function being native to JavaScript. In reality, it's not. Once we incorporate the function into your code, everything should work as expected.

I suspect that you're used to working on projects where certain utility functions are provided by an external script or library.

<script>
  function showElement(id) {
    document.getElementById(id).style.display = 'table-row'; 
    // or just '' for a more generic implementation
  }
</script>

<table cellspacing=0 cellpadding=7 border=1>
  <tr bgcolor=#efefef>
    <td></td>
    <td>Date</td>
    <td>DATA</td>
    <td>MORE DATA</td>
    <td>Method</td>
  </tr>
  <tr>
    <td>
      <button onclick="javascript:showElement('abcdata')" style="padding:4px" class=verd8> SHOW NEW ROW </button>
    </td>
    <td>Jan 22, 2022</td>
    <td>SOME DATA</td>
    <td>SOME MORE</td>
    <td>BUTTONDROP</td>
  </tr>
  <tr id="abcdata" style="display:none;">
    <td colspan=5>
      SHOW NEW ROW ACROSS ALL CELLS : sfdgsdfgs hlahhfa la dfl dfljhsd flhsd flhsdf lhdsfh asf alhd a</td>
  </tr>
</table>

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

Modify the value during the oninput event in TypeScript

I am trying to dynamically change a span element based on the input value when the event 'input' is triggered. Below is my HTML code: <div class="slidecontainer"> <input type="range" min="1" max="1000" value="50" class="slider" id= ...

Express server continuously returning 404 error for all requests originating from the index page

Experiencing a challenge with the express/gulpfile.js code. Express can serve the index.html without issue, but it fails to navigate to the lib/* directory resulting in all requests for resources at the top of my index.html returning 404 errors. Browser-s ...

The transcription generated by the Google speech-to-text service came back blank when processing the audio captured by the MediaRecorder API within

I am currently working on a project involving transcribing speech into text and I am utilizing the Google Speech to Text API with Next.js/React. I'm recording audio using the MediaRecorder API of a web browser. Interestingly, when I use the audio reco ...

Displaying JavaScript validation errors on a Bootstrap 4 .btn-group-toggle

I have created a star rating user interface using the Bootstrap 4 .btn-group.btn-group-toggle as shown in the code snippet below: <div class="form-group"> <div class="btn-group btn-group-toggle" data-toggle="buttons" aria-label="Rate this"> ...

What is the best way to configure a metered subscription plan on Stripe that invoices annually but bills extra fees for overage on a monthly basis

I'm in the process of setting up a subscription system on stripe that includes a plan with 5000 monthly credits for a flat $299 yearly fee. My goal is to charge customers who exceed their monthly credit limit by the end of each month. For example, if ...

How to center an image within a WordPress .php file

Could someone please assist with centering the image in the code snippet below? add_action('woocommerce_after_add_to_cart_button', 'add_content_on_add_to_cart_button'); function add_content_on_add_to_cart_button() { echo &qu ...

What is the best way to vertically flip a background image that is repeating along the y axis in CSS?

I am in the process of developing a mobile web app and I need assistance with flipping the background image when it repeats along the y-axis. Can someone guide me on how to achieve this using CSS or JavaScript? https://i.stack.imgur.com/b107V.jpg var el ...

Show only the relevant content, if no matches are found then indicate this

I am currently filtering elements based on their data-attribute values and I want to show some HTML content if there are no matches found. My knowledge of JS/jQuery is limited, so I'm not sure how to achieve this. I would appreciate any guidance on ho ...

Steps for setting up node-openalpr on a Windows 10 system

While attempting to install npm i node-openalpr, an error is occurring: When using request for node-pre-gyp https download, I encounter a node-pre-gyp warning and error message. The package.json for node-openalpr is not node-pre-gyp ready, as certain pr ...

Menu collapse button failing to Show content

My navigation menu button is not functioning correctly. I am currently working on this project using CodePen, so Bootstrap is already integrated into the code. <div class="navbar-header"> <button type="button" class="btn navbar-toggl ...

While attempting to populate an array with data, I encountered the issue of receiving 'undefined' values within the

https://i.sstatic.net/YB5kX.pngIs there anyone who can assist me in resolving this challenge? I've been grappling with this problem for the past three days, and using jquery Ajax is a new experience for me. My goal is to dynamically populate a calend ...

An alternative to Object.defineProperty for IE8

In the javascript code snippet below (taken from a referenced plugin), an AutosizeInput function is defined: var AutosizeInput = (function () { function AutosizeInput(input, options) { var _this = this; this._input = $(input); ...

After clicking on a specific href element with a designated class, trigger the display of a custom dialog styled using CSS

I recently added a unique class to certain links on my website. When these specific links are clicked, I want them to trigger a customized dialog box. My goal is to modify the CSS of this special dialog box. Only links with this particular class should ...

Automatically wrapping and centering characters within pre tags in HTML

I decided to add a box to highlight certain queries on a specific page, rather than the entire website. In order to test out this change, I added an inline style. I found that I had to adjust the characters within the pre tags in order to make them fit ins ...

How are the script name and script file connected in WordPress enqueuing?

When adding a jQuery script to the function.php file using the enqueue method, how does the script name relate to the actual file that contains the jQuery code? Is the script name arbitrary, or is it derived from either the file name or the actual script w ...

Managing browser back button functionality

I've been struggling to find a solution for handling the browser back button event. I would like to prompt the user with a "confirm box" if they click on the browser back button. If they choose 'ok', I need to allow the back button action, ...

Error: Psuedo After element fails to display

I've been struggling to get a small chevron to display as a pseudo-after element, but for some reason it's just not showing up. I've tried adjusting the z-index without any luck. Any suggestions on what I might be doing wrong? Here's ho ...

Display a div element on the page after 10 seconds of loading

Recently, I managed to get this script working successfully where it fades out within 20 seconds. However, I am looking to modify it so that it takes only 10 seconds to display after the page loads. Any suggestions on what I should change in the code? jQu ...

Having difficulty shrinking the excessive gap between the image and text

https://i.sstatic.net/7Wu8J.jpg I have created an app and added inline styling to make the image and text appear next to each other. However, there seems to be some extra space between the image and text, and the text "Demo Analysis Application" is split ...

Steps to seamlessly integrate puppeteer with an active Chrome instance or tab

Is there a way to connect puppeteer to an already open Chrome browser and control a specific tab? I believe it may involve starting Chrome with the --no-sandbox flag, but I am unsure of the next steps. Any assistance on this matter would be greatly apprec ...