Im new to Jquery and i need to convert this js file from js to Jquery. The code i provided probably has many simple mistakes, but i am getting the syntax error on var textnode = $(.text(task.value));
(If there is any extra mistakes please let me know)
var buttontask = $("#buttontask");
var task = $("#task");
var list1 = $("#list1");
var Delete = $("#delete");
var Delete1 = $("#delete1");
buttontask.on('click', function () {
var newE = $('<li></li>');
var textnode = $(.text(task.value));
var buttondelete = $('#DIV');
var textnodeX = $(.text('X'));
Delete.appendChild(buttondelete);
newE.appendChild(textnode);
buttondelete.appendChild(textnodeX);
newE.on('click', function() {
this.parentNode.removeChild(this);
});
buttondelete.on('click', function(){
this.parentNode.removeChild(this);
newE.parentNode.removeChild(newE);
});
code i want to convert to jq
var buttontask = document.getElementById("buttontask");
var task = document.getElementById("task");
var list1 = document.getElementById("list1");
var Delete = document.getElementById("delete");
var Delete1 = document.getElementById("delete1");
buttontask.addEventListener('click', function () {
var newE = document.createElement('LI');
var textnode = document.createTextNode(task.value);
var buttondelete = document.createElement('DIV');
var textnodeX = document.createTextNode('X');
If $("#task") refers to a textarea you need to use $("#task").text() to store its value. if it refers to an text input, you can use $("#task").val();
Also be careful of using word delete for variables names in javascript, I know that the lower case version is reserved.