Changing from javascript to Jquery this is the code in javascript Can someone pl
ID: 3583957 • Letter: C
Question
Changing from javascript to Jquery
this is the code in javascript
Can someone please change this code from javascript to jquery? Thank you so much!!
<script type="text/javascript" language="javascript"> function addrow() { var tbl = document.getElementById("tbe"); var lastRow = document.getElementById("tbe").getElementsByTagName("TR").length; if(lastRow <= 10) { var iteration = lastRow; var row = tbl.insertRow(lastRow); var cellLeft = row.insertCell(0); var textNode = document.createTextNode(iteration); cellLeft.appendChild(textNode); var cellRight = row.insertCell(1); var e1 = document.createElement('input'); e1.type = 'text'; e1.name = 'T2'; cellRight.appendChild(e1); var cellRight2 = row.insertCell(2); var e2 = document.createElement('input'); e2.type = 'text'; e2.name = 'T1'; cellRight2.appendChild(e2); var cellRight3 = row.insertCell(3); var e3 = document.createElement('input'); e3.type = 'text'; e3.name = 'T1'; cellRight3.appendChild(e3); var cellRight4 = row.insertCell(4); var e4 = document.createElement('input'); e4.type = 'text'; e4.name = 'T1'; cellRight4.appendChild(e4); var cellRight5 = row.insertCell(5); var e5 = document.createElement('input'); e5.type = 'text'; e5.name = 'T1'; cellRight5.appendChild(e5); } else { window.alert("Sorry! You cannot add more than 10 rows..."); } } function removerow() { var tbl = document.getElementById("tbe"); var lastRow = tbl.rows.length; if (lastRow > 2) tbl.deleteRow(lastRow - 1); else window.alert("Sorry! You cannot remove any more rows..."); } </script>Explanation / Answer
// <script src="jquery-3.1.1.min.js"></script> add this to your html page
function addrow(){
var tbl = $("#tbe"); //in jquery it is equivalent to document.getElementById('tb'). (#) is use for id (.) is for class
var lastRow = $("#tbe").$("[name='TR']").length;
if(lastRow <= 10){
var iteration = lastRow;
var row = tbl.insertRow(lastRow);
var cellLeft = row.insertCell(0);
var textNode = $(iteration).createTextNode();
$(cellLeft).appendChild(textNode);
var cellRight = row.insertCell(1);
var e1 = $('input').createElement();
e1.type = 'text';
e1.name = 'T2';
$(cellRight).appendChild(e1);
var cellRight2 = row.insertCell(2);
var e2 = $('input').createElement();
e2.type = 'text';
e2.name = 'T1';
$(cellRight2).appendChild(e2);
var cellRight3 = row.insertCell(3);
var e3 = $('input').createElement();
e3.type = 'text';
e3.name = 'T1';
$(cellRight3).appendChild(e3);
var cellRight4 = row.insertCell(4);
var e4 = $('input').createElement();
e4.type = 'text';
e4.name = 'T1';
$(cellRight4).appendChild(e4);
var cellRight5 = row.insertCell(5);
var e5 = $('input').createElement();
e5.type = 'text';
e5.name = 'T1';
$(cellRight5).appendChild(e5);
}
else{
$("Sorry! You cannot and more than 10 rows...").dialog();
}
}
function removerow(){
var tbl = $("#tbe");
var lastRow = tbl.rows.length;
if (lastRow > 2) tbl.deleteRow(lastRow - 1);
else $("Sorry! You cannot remove any more rows...").dialog();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.