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

316
Visualizações
Why can I not expand the container?

I use css to expand/collapse containers (ExpandableBoxContainer) within a parent container (SnippetContainer). There is a button in each expandable container for copying the code put in readonly textarea with this code (#248 - #263):

/* Highlight - Copy to Clipboard */
<script>
  document.getElementById("SnippetContainer").addEventListener("click", function(e) {

  let tgt = e.target.closest("input");
  if (tgt && tgt.matches(".copyBtn")) {
    const textarea = tgt.nextElementSibling;
    textarea.select();
    tgt.value = 'COPIED. Paste in SOURCE view!!!';
    document.execCommand('copy')
  } 
  else 
    tgt = e.target.closest("textarea");

  if (tgt.matches("[name=code]")) tgt.select()

})

</script>

The page structure is about like this:

<div id="SnippetContainer">
    <div class="ExpandableBoxContainer">
        <input...>
        <textarea>
            ...code snippet...
        </textarea>
    </div>
    <div class="ExpandableBoxContainer">
        <input...>
        <textarea>
            ...code snippet...
        </textarea>
    </div>
</div>

On expanding the CodeBoxContainer, the console returns: enter image description here

I can't find the reason and any fix to it.

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

0

You get the error at if (tgt.matches("[name=code]")) tgt.select() if tgn is null.

tgn is null if you click either at SnippetContainer or a descendant of it that is neither input nor textarea.

You would need to change if (tgt.matches("[name=code]")) tgt.select() to if (tgt && tgt.matches("[name=code]")) tgt.select() to make the error vanish.

But it is not fully clear if the logic that you have in your code is really correct, it at least looks highly suspicious.

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