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

198
Visualizações
why 'this' is undefined in my JQ funtion?

"this" is not working show_siblings

function addHeading(){
        $(".content").append("<h1 class='content_heading'>Heading <span onclick='show_siblings()' ><svg xmlns='http://www.w3.org/2000/svg' height='18' width='20'><path d='M5.688 11.083q-.459 0-.771-.323-.313-.322-.313-.76 0-.458.323-.771.323-.312.761-.312.458 0 .77.323.313.322.313.76 0 .458-.313.771-.312.312-.77.312Zm4.312 0q-.458 0-.771-.323-.312-.322-.312-.76 0-.458.323-.771.322-.312.76-.312.458 0 .771.323.312.322.312.76 0 .458-.323.771-.322.312-.76.312Zm4.312 0q-.458 0-.77-.323-.313-.322-.313-.76 0-.458.313-.771.312-.312.77-.312.459 0 .771.323.313.322.313.76 0 .458-.323.771-.323.312-.761.312Z'/></svg><div class='contentChildOptions'><button>Copy</button><button>Duplicate</button><button>Delete</button></div></span> </h1>");
        $(".content_heading").attr("contentEditable","true");
        $(".content_heading > *").attr("contentEditable","false");
        document.getElementById("heading_options").style.display = "block";
    }
function show_siblings(){              
    $(this).children().toggleClass("showElement");
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

```this`` reference missing in your code

function show_siblings(){              
    $(this).children().toggleClass("showElement");

See the example I demystifying this and that keyword

let element1 = document.getElementById("element1");
let element2 = document.getElementById("element2");

let toggle = true;

function toggleFunc( that ) {
  toggle = !toggle;
  that.setAttribute("data-show", toggle );
}
[data-show="false"] {
 color: red
}

[data-show="true"] {
 color: green
}
<div id="toggle" onclick=toggleFunc(this)>Click here: 1</div>

<div id="showElement" onclick=toggleFunc(this)>Click here: 2<div>

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