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

142
Visualizações
How do I pass between children by jQuery?

$('[data-target="#exampleModal"]').on("click", function () {
    var element = $(this).parent();
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<div class="row">
        <div class="col-md-4 col-lg-3" id="">
            <button data-toggle="modal" data-target="#exampleModal">
                <img src="./img/watch-page.png" alt="" class="w-100" />
            </button>
        </div>

        <div class="col-md-4 col-lg-3">
            <button data-toggle="modal" data-target="#exampleModal">
                <img src="./img/watch-page.png" alt="" class="w-100" />
            </button>
        </div>

        <div class="col-md-4 col-lg-3">
            <button data-toggle="modal" data-target="#exampleModal">
                <img src="./img/search-page.png" alt="" class="w-100" />
            </button>
        </div>
   </div>

How can I find out the order of the element for all of the children?

And how can I move to the next child or the one before it?

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

0

First, you were not selecting the elements properly. When you call

$('[data-target="#exampleModal"]')

It return array of elements so you should loop over them and then add events for click.

You can see below, index is the order of the button and button is the element so you can walk from there to reach parent etc.

$.each($('[data-target="#exampleModal"]'), function(index, button){
    $(button).on("click", function () {
        var element = $(this).parent();
        console.log(element);
    });
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<div class="row">
        <div class="col-md-4 col-lg-3" id="">
            <button data-toggle="modal" data-target="#exampleModal">
                <img src="./img/watch-page.png" alt="" class="w-100" />
            </button>
        </div>

        <div class="col-md-4 col-lg-3">
            <button data-toggle="modal" data-target="#exampleModal">
                <img src="./img/watch-page.png" alt="" class="w-100" />
            </button>
        </div>

        <div class="col-md-4 col-lg-3">
            <button data-toggle="modal" data-target="#exampleModal">
                <img src="./img/search-page.png" alt="" class="w-100" />
            </button>
        </div>
   </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