Try to search your question here, if you can't find : Ask Any Question Now ?

add tr in the table by using jquery

HomeCategory: stackoverflowadd tr in the table by using jquery
sourav asked 1 week ago

I use HTML to add TR in the table. I want to use Jquery to do it.
Here is my code.

HTML

<table class="table">
      <thead>
        <tr>
          <th>STT</th>
          <th>MSSV</th>
          <th>NAME</th>
          <th>MATH</th>
          <th>ENGLISH</th>
          <th>LITERATURE</th>
          <th>GRADE</th>
          <th>FUNCTION</th>
        </tr>
      </thead>
      <tbody id="ds-sv">
      </tbody>
    </table>

Jquery

$("#addBtn").click(function() {
        var mssv = $("#mssv").val();
        var name = $("#name").val();
        var math = $("#math").val();
        var eng = $("#eng").val();
        var sinh_vien = [mssv, name, math, eng]
        dssv.push(student);
        refresh_input();
        var html = "";
        for (var i = 0; i < dssv.length; i++) {
            var sv = dssv[i];
            var stt = i + 1;
            var sv_html = "<tr><td>" + stt + "</td><td>" + sv[0] + "</td><td>" + sv[1] + "</td><td>" + sv[2] + "</td><td>" + sv[3] + "</td></tr>";
            html = html + sv_html;
        }
        $('#ds-sv').html(html);
    });

I want these codes were written by Jquery

for (var i = 0; i < dssv.length; i++) {
            var sv = dssv[i];
            var stt = i + 1;
            var sv_html = "<tr><td>" + stt + "</td><td>" + sv[0] + "</td><td>" + sv[1] + "</td><td>" + sv[2] + "</td><td>" + sv[3] + "</td></tr>";
            html = html + sv_html;
        }

I am a newbie. I try some code but it did not work.

1 Answers
Best Answer
naveen answered 1 week ago
Your Answer

5 + 7 =

Popular Tags

WP Facebook Auto Publish Powered By : XYZScripts.com