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

123
Visualizações
How do I convert HTML code into a JavaScript String variable?

I am wondering how I can convert my HTML code that has been garbed with my document.getElementById("landornot") function and convert it into a string. For example right now when I console.log it I get <li class="listing-property-type" id="landornot"><span class="label">Property Type: </span><a href="https://axisutahdev.wpengine.com/property-types/land/" rel="tag">Land</a></li>

What I want is it to be in a string so it should look like this '<li class="listing-property-type" id="landornot"><span class="label">Property Type: </span><a href="https://axisutahdev.wpengine.com/property-types/land/" rel="tag">Land</a></li>'

I haven't been able to find any helpful resource online any help would be appreciated.

My Code:

<script>
    window.onload = (event) => {
        const land = document.getElementById("landornot");
        console.log(land);
        
        if (land === '<li class="listing-property-type" id="landornot"><span class="label">Property Type: </span><a href="https://axisutahdev.wpengine.com/property-types/land/" rel="tag">Land</a></li>') {
            console.log('Right Page')
        } else {
            console.log('Wrong Page')
        }
    };
</script>
about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

Have you tried using the .outerHTML property? E.g. console.log(land.outerHTML);

about 4 years ago · Juan Pablo Isaza Relatório

0

    <script>
        window.onload = (event) => {
            const land = document.getElementById("landornot");
            land = land.outerHTML;
            console.log(land);
            
            if (land === '<li class="listing-property-type" id="landornot"><span class="label">Property Type: </span><a href="https://axisutahdev.wpengine.com/property-types/land/" rel="tag">Land</a></li>') {
                console.log('Right Page')
            } else {
                console.log('Wrong Page')
            }
        };
    </script>

you need element.outerHTML

about 4 years ago · Juan Pablo Isaza Relatório

0

Maybe you can use the built in function: Tostring()

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