Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

108
Views
ReferenceError: <función> no está definida en HTMLElement.onclick

Estoy tratando de permitir que un usuario ingrese varias etiquetas y pueda eliminarlas de la matriz mediante el uso de un cuadro de texto, un ejemplo sería cómo stackoverflow le permite agregar etiquetas al hacer una pregunta, he podido agregar los valores a la matriz, sin embargo, recibo un error cuando ejecuto la función de eliminación. este es el javascript que he escrito a continuación:

 <script type="module"> import {getDatabase, ref, set, child, get} from "https://www.gstatic.com/firebasejs/9.6.6/firebase-database.js"; const db = getDatabase(); const ul = document.querySelector(".statementbox"); const input = ul.querySelector('.inputstate'); let tags = []; function createTag(){ //removing li tas before adding so there will be no duplication ul.querySelectorAll("li").forEach(li => li.remove()); tags.slice().reverse().forEach(tag =>{ let liTag = `<li>${tag} <i class="fas fa-times" onclick="remove(this,'${tag}')"></i> </li>`; ul.insertAdjacentHTML("afterbegin", liTag); //adding li inside ul tag }); } function remove(element, tag){ let index = tags.indexOf(tag); // getting removing tag index tags = [...tags.slice(0, index), ...tags.slice(index + 1)]; // removing the tag from the array console.log(tags); } function addTag(e){ if (e.key === "Enter") { let tag = e.target.value.replace(/\s+/g, ' '); //removing unwanted spaces from tag if (tag.length > 1 && !tags.includes(tag)) { //if tag length is greater than one and does not already exist tag.split(',').forEach(tag => {//splitting each tag from comma tags.push(tag); //adding tag to the array createTag(); }); } e.target.value = ""; } } input.addEventListener("keyup", addTag); </script>

No entiendo la causa del error porque investigué y la función no está dentro de otra función ni está vinculada a un script con src ni está envuelta dentro de otra función, intenté agregar remove() en un script separado y lo registró en la consola, sin embargo, cuando hago esto, mi matriz aparece en blanco.

Por favor, indique qué hacer, gracias de antemano.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!