table - Javascript: Identify row by ID, then one of it's cells by class -


given table:

<table border="1" width="200" id="table1" cellspacing="0" cellpadding="0" style="border-collapse: collapse" bordercolor="#cb2f7f">     <tr id="st_ppp">         <td width="60%" class="totallabels">price per piece</td>         <td width="39%" align="right" class="totalelements">unknown</td>     </tr>     <tr id="st_qty">         <td width="60%" class="totallabels">quantity</td>         <td width="39%" align="right" class="totalelements">unknown</td>     </tr>     <tr>         <td width="60%">&nbsp;</td>         <td width="39%" align="right">&nbsp;</td>     </tr>     <tr>         <td width="60%" class="subtotallabel">sub-total:</td>         <td width="39%" align="right" class="subtotal">unknown</td>     </tr> </table> 

i'd following pseudo code:

docuement.getelementbyid("st_ppp").[td class totalelements].innerhtml="newprice"; docuement.getelementbyid("st_qty").[td class totalelements].innerhtml="newqty"; 

i'm open suggestions of other changes html make js easier work with.

if you're not worried compatibility internet explorer 7 , earlier, queryselector perfect (but if go way, credits @sirko instead):

document.queryselector('#st_ppp > .totalelements').innerhtml = "newprice"; 

if you're using jquery, it's excellent that:

$('#st_ppp > .totalelements').text('newprice'); 

otherwise, loop work:

var priceperpiece = document.getelementbyid('st_ppp'); var i, c;  for(i = 0; c = priceperpiece.children[i]; i++) {     if((' ' + c.classname + ' ').indexof(' totalelements ') > -1) {         c.innerhtml = 'newprice';         break;     } } 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -