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

214
Views
Al navegar por elementos HTML con forEach, la función getElementsByClassName no funciona en estos elementos.

Déjame tratar de explicarte, pero lo entenderás mejor cuando veas los códigos. Obtengo mis elementos div con la función getElementsByClassName y luego los convierto en una matriz con la función Array.from() . Mientras navego por esta matriz con la función forEach, envío cada elemento a una función. En esta función, el parámetro item representa mi elemento. Puedo mostrar este elemento con console.log(item) e incluso enumerar sus elementos secundarios con item.children . Sin embargo, cuando selecciono este div con document.getElementById() usando Inspect(F12) y luego ejecuto la función getElementsByClassName solo en este div, no obtengo un error, pero en la función item.getElementsByClassName que escribí en la página html, Recibo el error 'Uncaught TypeError: item.getELementsByClassName is not a function' .

Dejo el código que escribí a continuación. Error en la función registerClickOrdering .

 function registerClickHandler() { $('.remove_question_div').click(function() { var removedId = parseInt($(this).parent().attr('id').split('-').slice(-1)) $(this).parent().remove(); var questions = Array.from(document.getElementsByClassName('questions')).slice(removedId-1) console.log(questions) questions.forEach((item, index) => {registerClickOrdering(item, index)}) }); } const registerClickOrdering = (item, index) => { console.log(item) item.id=`question_div-${index+2}` var questionCounterLbl = item.getELementsByClassName('question-counter')[0] questionCounterLbl.textContent = `${index+1}. Soru` var questionTitle = item.getELementsByClassName('question-title')[0] questionTitle.name = `question-${index+1}` questionTitle.id = `id_question-${index+1}` var answerInputs = Array.from(item.getELementsByClassName('answers-input')) answerInputs.forEach((item) => { item.name = `answer-${index+1}` }) }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Estás haciendo todo bien excepto por una pequeña cosa con la que un linter podría ayudarte en el futuro...

Cambiar getELementsByClassName a getElementsByClassName

A todos nos pasa en algún momento.

about 4 years ago · Juan Pablo Isaza Report
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!