简体   繁体   中英

Update cell value in Table - repeater using jQuery

I have repeater and it gets a column value from modalpopup. I need to set that on 3rd from last and 2nd cell anchor tag. Below is my code snippet. It is working on IE, but not in Firefox, Safari and Chrome.

{   
  var repeater = $("#pubRepeater");
  var numberofrows = repeater.find('tr').length;
  var lastcell = repeater.find('tr')[numberofrows - 3];
  lastcell.childNodes[1].childNodes[0].innerText = 'New Value';
}

Try the following,

       lastcell.childNodes[1].childNodes[0].html('New Value');

                          or

       lastcell.childNodes[1].childNodes[0].text('New Value')

Hope this helps..

It looks like the issue is that while you're using jQuery, you're not using at all the way. The.innerText property is specific to IE, so why not use the method jQuery provides?

$('td a', lastcell).text('New Value');

If the td is the last td in the row, then:

$('td:last a', lastcell).text('New Value');

If you are trying to update the actual HTML rather than the text, then use.html instead of.text

The second arguement in the $() selector is the scope in which it should look for the elements in the first arguement. Since you've already found the last row, it's far more efficient to tell jQuery to look for the 'td:last a' elements only in that row.

Also, by using the 'td:last a' instead of childNode[0].childNode[1], you make your code much more extensible. Now, if you add more columns or additional elements to the last column, you won't have to go and change your childNode indexes to match.

Hope this helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM