Bug Tracker

Opened 9 years ago

Closed 9 years ago

#8469 closed bug (invalid)

nth-child selector problem in certain browsers

Reported by: random.genius Owned by:
Priority: undecided Milestone: 1.next
Component: unfiled Version: 1.5.1
Keywords: Cc:
Blocked by: Blocking:

Description

I posted this on the forum but no replies. I'm having trouble with the selector to get/set data in certain columns. The example should place 'A' in the 3rd column but on the first row it places it in the 4th column. This seems to work fine in IE8 & Firefox 3.6 but doesn't work in Chrome 9 and Safari 5.

  $(document).ready(function(){

	var originalRow=$('#row1').html();
	
	function newRow(r){
		var col=1
		var str=""
		str = '<tr id="row'+r+'">';
		str += originalRow;
		str += '</tr>';
		return str;
	}
		
	rows=""
	for(row=2;row<5;row++){
	  rows=rows+newRow(row)
	}
	
	$('#editlist tr:last').after(rows);
	$('#editlist tbody tr td:nth-child(3) input').val("A");	
  });

<form name="form1" method="post" action="">
  <table width="100%"  border="0" cellpadding="4" cellspacing="0" id="editlist">
  <thead>
    <tr>
      <td>Field 1</td>
      <td>Field 2</td>
      <td>Field 3</td>
      <td>Field 4</td>
    </tr>
	</thead>
	<tbody>
	  <tr id="row1">
      <td><input type="checkbox" value="checkbox"></td>
      <td>text</td>
      <td><input type="text" size="13"></td>
      <td><input type="text" size="10"></td>
    </tr>
	</tbody>
  </table>
</form>

I originally noticed this problem when I was using .each. For example to just console.log the value of a certain column. I would find that the second time I call it, it would display the correct result.

jsFiddle example http://jsfiddle.net/dreaminblue/Lenqt/

Change History (3)

comment:1 Changed 9 years ago by random.genius

As a side note, I noticed that if the second column becomes an input as well it fixes it. I can't see how "tbody tr td:nth-child(3) input" is effected by this, shouldn't it find the nth-child of td regardless of what's contained within it?

Last edited 9 years ago by random.genius (previous) (diff)

comment:2 Changed 9 years ago by random.genius

Well I think I found my problem, simply putting a colon before the input selector fixes it for me although I still think there's an underlying problem still there.

comment:3 Changed 9 years ago by dmethvin

Resolution: invalid
Status: newclosed

You were right in posting on the forum, since this is the bug tracker. Sorry nobody answered but that may mean they either didn't have the answer or didn't understand the question.

Note: See TracTickets for help on using tickets.