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

296
Visualizações
Javascript to get post title from an elementor post template

I'n new in Javascript so please excuse me if this is a silly question.

Using Elementor pro, I'm trying to get the post title from a custom post type loop (made with ele custom skin plugin) shown in a posts widget, using javascript (in the client side).

In my loop template, the post title is in a heading title (set with an Elementor dynamic tag). When clicking on it, I should get the title in a variable with something like this:

In the loop:

<script>
    var My_Heading = document.getElementById('My_Heading_Id');

    My_Heading.onclick = function(event){ 

        //Get the post title
        var StPostTitle = document.getElementById('My_Heading_Id').getElementsByTagName('a')[0].firstChild.data;

        console.log(StPostTitle);

        //Do something with StPostTitle ...

                        };
</script>

This only works when clicking on the first item in the loop. Clicking on any other item, either gives the same first item PostTitle or gives nothing. Tried with a button instead of heading with same result.

Is there some way to get any specific item title from the loop with javascript (not having to touch server php files)?

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

0

Thank you Jcl for the clue.

What I've done is to get the clicked element with the window.onclick event, this way:

 window.onclick = e => {
    var StPostTitle = e.target.innerHTML;

    // .........
} 

... and that's what i needed ;)

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