-1

In the process of converting my code from Jquery to Vanilla JS I have this code snippet that I can't convert:

function updateTextBox(nehemyah) {
  var delfino = $("#campotxt").val().split("\n");
  delfino.remove(nehemyah);
  $("#campotxt").val(delfino.join("\n"));
}

I tried this:

let camPito = document.getElementById("campotxt");
function updateTextBox(nehemyah) {
    let delfino = camPito.value;
    delfino = delfino.split("\n");
    delfino = delfino.remove(nehemyah);
    delfino = delfino.join("\n");
  }

The idea is that this textarea is cleared line per line once I press a button. If I use that Jquery snippet it works without problem.

1 Answers1

0

Array.prototype.remove() is not a standard method, so I guess you've defined that elsewhere in your code. It has nothing to do with jQuery.

Since this line isn't jQuery, there's no reason to change it. Presumably it doesn't return the array, it just modifies it in place, so you shouldn't assign the result back to the variable.

You're not assigning the final result back to the value of the input.

function updateTextBox(nehemyah) {
  let camPito = document.getElementById("campotxt");

  let delfino = camPito.value.split("\n");
  delfino.remove(nehemyah);
  camPito.value = delfino.join("\n");
}
Barmar
  • 741,623
  • 53
  • 500
  • 612
  • Working, thank you so muuuuch bro – SadDeepLoper Sep 08 '22 at 22:48
  • I asked [another question](https://stackoverflow.com/q/73664430/19856237) on StackOverflow about a problem converting AJAX from Jquery to Vanilla JS, do you think you could help me? I would really appreciate it :( – SadDeepLoper Sep 09 '22 at 16:18