Updated:
I have a JavaScript function inserted in a button. Just want to convert some of its jQuery codes to pure js coz I can't access codes with $(this).
My Code:
function editcheck(el) {
$(el).parent().parent().remove();
var tableData = $(el).closest('#paytable tr').children("td").map(function () {
return $(el).text();
}).get();
$('#checkamount').val($.trim(tableData[1]));
}
code/function before calling the editcheck:
var table = document.getElementById('paytable');
table.innerHTML += '<tr id="checktitle" style="border: none;"><td width="137px"><label>CHECK</label></td>' +
'<td class="rowAdd" width="125px">' + checkamounts.join("") + '</td>' +
'<td width="127px">' + checknos.join("") + '</td>' +
'<td style="display: none">' + dbank.join("") + '</td>' +
'<td style="display: none">' + draweedesc.join("") + '</td>' +
'<td style="display: none">' + pickercheck.join("") + '</td>' +
'<td><button title="Edit" onclick="editcheck(this)" type="button" style="width: 30px; height: 18px"><img src="images/editimg.png" width="13" height="13"></button></td>';
P.S I can't use $("#elementid").click(function() because the line will exist after appending it.
onclick="editcheck.call(this)"Also instead of doing.parent().parent()you could just do$(this).closest('tr')editCheck()work without jQuery even though that won't solve their actual problem. It appears the reason they are asking for that is because they aren't passingthisproperly to their inline event handler which does not require or even benefit from converting the jQuery to plain javascript. I'd say that Arun's answer solves the OP's issue without removing the jQuery. This is a classic example of a question asking how to do what they think is the solution when they really should have just described the problem and asked for solutions to the problem.