1

I'm very new to javaScript and I'm trying to remove two td's but I can't manage to find a way of doing it.

These are the td's that I need to be removed in order to remove the spacing between the FIRST NAME and the LAST NAME. I also have to mention that I'm not allowed to edit the HTML directly.

<td class="error_label">
          <span id="ctl03" style="visibility:hidden;">Required Field</span>
        </td>

<td colspan="2" class="pd_question">
        <span id="lbl3"></span>
      </td>

Here is the whole code http://jsfiddle.net/w8z4nxa7/4/

Duicug
  • 51
  • 2
  • 9

2 Answers2

1

Intro

You could try to remove them, by using a getElementByClassName.

So you need two things:

document.getElementsByClassName to get the actual element.

Once you get the element you need to remove it. elem.parentNode.removeChild(elem).

Quick rough example

var elem = document.getElementsByClassName('error_label')[0];
elem.parentNode.removeChild(elem);

See: Remove element by id

Menelaos
  • 23,508
  • 18
  • 90
  • 155
1

In short, you have to select the element and then remove it using .remove() or removeChild(...)on its parent.

Timing is important, so that you don't try to select the elements before they are rendered on the page. For this, you put the <script> tag after the elements you want to work with or you add an onload or even better an addEventListener("DOMContentLoaded"):

document.addEventListener("DOMContentLoaded", function(event) {
   document.querySelector('.error_label').remove()
   // and so on
});
Ionică Bizău
  • 109,027
  • 88
  • 289
  • 474