javascript - Getting html of <td> -


i using following function try , html of element referencing row above (i feel have reason won't go into).

function test() {     var rowamount = $("#ordertable > tbody > tr").length;         for(i = 0; < rowamount; i++) {         $( "#ordertable > tbody > tr :eq(i)" ).setattribute( "id", "row" + (i + 1) );         }    alert($( "tr#row1" ).next().find( "td.qty" ).html()); } 

i using loop set id of rows have, ones wish reference from. inserting new rows depending on value within these.

the error getting line,

$( "#ordertable > tbody > tr :eq(i)" ).setattribute( "id", "row" + (i + 1) ); 

is returning error, undefined not function.

does know why?

thanks in advance. mike.

setattribute javascript function not jquery(you try use jquery object). can use jquery .attr() like:

$("#ordertable > tbody > tr :eq(" + + ")").attr("id", "row" + (i + 1));   

here example:

var = 1;  $("#ordertable > tbody > tr :eq(" + + ")").attr("id", "row" + (i + 1));
#row2 {    background: red;  }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <table id="ordertable">    <tbody>      <tr>        <td>1</td>        <td>2</td>        <td>3</td>      </tr>    </tbody>  </table>


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -