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

150
Visualizações
Showing actual HTML content in jQuery

I have an element with encoded html content as shown below.

<div class="hasTooltip"> 
    &lt;html&gt;........... //more html encoded text
</div>

When I click this element, I want the content to be shown in a new window and it works fine.

$('.hasTooltip').click(function() {
    var win = window.open("", "Title", "toolbar=no");
    win.document.body.innerHTML = $(this).html();
});

But the problem is that the window shows the html text with decoded values but not the actual html content with all styles.

I tried the below code but no luck as it shows no content. Any tips?

win.document.body.innerHTML = $(this).html().text();
about 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

Following code should work.

function unEscape( str ){
  str = str.replace(/&quot;/g,'"').replace(/&amp;/g,'&').replace(/&lt;/g,'<').replace(/&gt;/g,'>')
 return str;
}
var h = document.getElementById("hasTooltip").innerHTML;

console.log( unEscape(h) )
<div id="hasTooltip"> 
    &lt;html&gt;&lt;/html&gt;
</div>

about 4 years ago · Santiago Trujillo Relatório

0

Here is your solution

if you you are unable to run your code over here please check jsfiddle

https://jsfiddle.net/sq3Ljwnt/

$('.hasTooltip').click(function() {
    var win = window.open("", "Title", "toolbar=no");
    win.document.body.innerHTML = $("textarea").val();
});
textarea{
  height:200px;
  width:100%;
  border:none !important;
  background:none;
  resize: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<div class="hasTooltip"> 
<textarea>
<html>
  <h1>
  This is test
  </h1>
  <p>
  More HTML ...
  </p>
</html>
</textarea>
</div>

about 4 years ago · Santiago Trujillo 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