0

I have the function below

<tr id="Player123"></tr>

function remove() {
    var child = document.getElementById("Player123");
child.parentElement.removeChild(child);
}

I want it to remove an entire table row.

For some reason it works perfectly on my local host, but on the web serber all it does is remove the button that calls the function.

Does anyone know why?

Tunna182
  • 343
  • 3
  • 16
  • 1
    This is client-side code, it works the same way wherever you host the page. Something else must account for it working in one place but not another. – Jamiec Nov 02 '15 at 13:46
  • That's what I was thinking. That's why I'm so puzzled now. – Tunna182 Nov 02 '15 at 13:50
  • 2
    @Tunna182, Try creating fiddle of this. Or provide more context of the situation! – Rayon Nov 02 '15 at 13:50
  • 1
    Note that [*parentElement*](http://www.w3.org/TR/dom/#dom-node-parentelement) is a DOM 4 property, [*parentNode*](http://www.w3.org/TR/DOM-Level-3-Core/core.html#ID-1060184317) has been around a lot longer and is much more widely supported. – RobG Nov 02 '15 at 14:01
  • Thanks @RayonDabre - I should have done this in the first place: https://jsfiddle.net/0g9vw4jp/ – Tunna182 Nov 02 '15 at 14:07
  • @RobG, you have just given me a huge hand! It would appear the people who reported this error may be using an older browser than mine. Can't believe I didn't even consider that. Thank you. If you make that comment an answer I'll tick it. – Tunna182 Nov 02 '15 at 14:12
  • 1
    @Tunna182—they must be using Firefox, or maybe Mozilla, surely not Netscape! ;-) see [*Difference between DOM parentNode and parentElement*](http://stackoverflow.com/questions/8685739/difference-between-dom-parentnode-and-parentelement). – RobG Nov 02 '15 at 14:15
  • thanks for the read. I have a lot to learn hey.... thanks for helping me with this part! – Tunna182 Nov 02 '15 at 14:29
  • JavaScript runs on the client (eg web browser) as opposed to a server. There will not be disparities for clients between servers unless there is a disparity in the code being served, and/or how it is actually serving it. Could you send a link to the code on the server? – MrBizle Nov 02 '15 at 13:54
  • Thanks for looking. Here is a link to a JS fiddle. https://jsfiddle.net/0g9vw4jp/ – Tunna182 Nov 02 '15 at 14:08
  • seems to work fine https://jsfiddle.net/mqaqup2c/ You will be better setting up an event listener for the button, and running remove() on that – MrBizle Nov 02 '15 at 14:17
  • 1
    Ive got five mins will complete the fiddle for you :) – MrBizle Nov 02 '15 at 14:22
  • 1
    My comment got deleted? STRANGE :O https://jsfiddle.net/mqaqup2c/6/ there you go – MrBizle Nov 02 '15 at 14:50
  • @MrBizle I was thinking the same. I thought it must of been you, but wasn't sure why.... Anyway, I'm glad you're still here, and thanks heaps for your effort, but that JS still didn't work in Firefox. (it was great in IE though). – Tunna182 Nov 02 '15 at 21:00
  • https://jsfiddle.net/mqaqup2c/7/ – MrBizle Nov 03 '15 at 21:46
  • Sorry bro there were a few things that might have caused errors with the last example. replace() is native in later js specs and so might not have worked, we also had a function called .replace, I don't know if some browsers dont' like redeclaring functions more than others but perhaps so! – MrBizle Nov 03 '15 at 21:53

0 Answers0