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

130
Visualizações
Uncaught SyntaxError: expected expression, got ';'
var popupContent = '<a href="#tableofresults" class="modal-trigger" onClick="stopno='+feature.properties.busstopcode+'; nuscode="'+feature.properties.nuscode+'";">Click me!</a>';

I'm currently using Leaflet and want a popup with clickable text, which will run some Javascript to define the variables stopno and nuscode. However, in the GeoJSON data feature.properties.nuscode is a string and not an integer, and thus I need to use quote marks to define the variable nuscode.

However, if I were to use quote marks again it would cause issues as I am using inline JS in the onclick property for the <a> tag, and using quote marks causes "Unexpected end of input" errors. How do I remedy this?

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

0

As of ES2015, you could use backticks to create what is known as template literals (template strings).

You can encapsulate text in backticks and interpolate JavaScript so that your code is much neater. It also helps avoid any conflicting use of single/double quotation marks, and avoids having to escape (\) strings.

More can be read about it here on MDN

const popupContent = `<a href="#tableofresults" class="modal-trigger" onClick="stopno='${feature.properties.busstopcode}'" nuscode="${feature.properties.nuscode}">Click me!</a>`;
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