Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

234
Visualizações
Class not recognized in .html file

I have a class (for creating a custom form element) called ListOfDropdowns inside a .html file :

class ListOfDropdowns extends HTMLElement {
  
connectedCallback() {
let myParent = document.body
let array = ['Volvo', 'Saab', 'Mercades', 'Audi']
    let template = document.querySelector('#list-of-dropdowns-template').content;
    this.attachShadow({
      mode: 'open'
    }).appendChild(template.cloneNode(true));

    let add_button = this.shadowRoot.querySelector("#add");
    let remove_button = this.shadowRoot.querySelector("#remove");
    let list = this.shadowRoot.querySelector("#list");
    

    add_button.addEventListener('click', () => {
     
  var selectList = document.createElement('select')
  selectList.id = 'mySelect'
  selectList.style.display = 'block'
  myParent.appendChild(selectList)

  //Create and append the options
  for (var i = 0; i < array.length; i++) {
    var option = document.createElement('option')
    option.value = array[i]
    option.text = array[i]
    selectList.appendChild(option)
  }
  list.appendChild(selectList)
     
    });

    remove_button.addEventListener('click', () => {
     list.lastChild.remove()
    });
  }
}

customElements.define('list-of-dropdowns', ListOfDropdowns);

And some lines beneath the class, I have this code:

var VIA_ATTRIBUTE_TYPE = { TEXT:'text',
                       CHECKBOX:'checkbox',
                       RADIO:'radio',
                       IMAGE:'image',
                       DROPDOWN:'dropdown'
           ListOfDropdowns:'listofdropdowns'
                     };

But, I get an error at the line ListOfDropdowns:'listofdropdowns'.

 Uncaught SyntaxError: Unexpected identifier

Both the class ListOfDropdowns and VIA_ATTRIBUTE_TYPE are defined/declared inside the <script> tag inside the <body> tag in the .html file.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Based on the comment, I added a comma after DROPDOWN:'dropdown' and that resolved the error.

var VIA_ATTRIBUTE_TYPE = { TEXT:'text',
                       CHECKBOX:'checkbox',
                       RADIO:'radio',
                       IMAGE:'image',
                       DROPDOWN:'dropdown',
           ListOfDropdowns:'listofdropdowns'
                     };
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda