If you think a bug might affect users in the 57 release, please set the correct tracking and status flags for Release Management.

DOM: firstChild doesn't work every time

RESOLVED DUPLICATE of bug 26179

Status

()

Firefox
General
RESOLVED DUPLICATE of bug 26179
12 years ago
12 years ago

People

(Reporter: Dalibor Krleža, Unassigned)

Tracking

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

12 years ago
User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.3) Gecko/20060426 Firefox/1.5.0.3
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.3) Gecko/20060426 Firefox/1.5.0.3

I was trying to create javascript function for copying table row with all contents and appending new row at the end of the table. It happends that is some cases (depends on HTML) firstChild doesn't return proper object inside table cell. Instead od object inside table cell, as first child is returned #text. Small changes in HTML code and everything works properly.

Reproducible: Always

Steps to Reproduce:
1. Make HTML code which contains
<table id="my_table">
<tr>
  <td>
    <input name="a1" value="Test1">
  </td>
</tr>
</table>

2. Make javascript function for copying table row
function copy_row() {
  var t=document.getElementById("my_table");
  var old_row=t.rows[0];
  var new_row=t.insertRow(1);
  var old_cell_contents=old_row.cells[0].firstChild;
  var new_cell_contents=old_cell_contents.cloneNode(true);
  new_cell_contents.value="Test2";
  new_cell_contents.name="a2";
  var new_cell=new_row.insertCell(0);
  new_cell.appendChild(new_cell_contents);
}

3. Make a button which will call javascript function
<button type="button" onclick="copy_row();">Click me</button>

4. Load this in your browser and click on button
Actual Results:  
Function copy_row is terminated on setting new text input object's value. cloneNode didn't clone old text input object because firstChild didn't return old text input object. Same happends when using childNodes[0].

Expected Results:  
After click on button and calling copy_row function, second row in table should appear with new text input object. New text input object with name a2 and value Test2.

If you change HTML code like:
<table id="my_table">
<tr>
  <td><input name="a1" value="Test1"></td>
</tr>
</table>

everthing works properly!

Comment 1

12 years ago

*** This bug has been marked as a duplicate of 26179 ***
Status: UNCONFIRMED → RESOLVED
Last Resolved: 12 years ago
Resolution: --- → DUPLICATE
You need to log in before you can comment on or make changes to this bug.