Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Error on converting Jquery val().split() to Vanilla Javascript

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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");
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading