Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

163
Vistas
how to avoid from ajax call same function with .scroll(function() if i was click on another div with onclick

in this code you can see that i have two div tags that every one of them have not the same onclick="" function call, the problem is when i click on one of them and then click on enother one the .scroll(function() works also from the first clicked function, this example with alert only,

<div class="first_div_class" onclick="firstFunction();">First Div</div>
<div class="second_div_class" onclick="secondFunction();">Second Div</div>
<div class="result"></div>
<script class="functions">

        function firstFunction(){

          var one = '<?php echo $someValueOne; ?>';
          var two = '<?php echo $someValueTwo; ?>';                      

                    $.ajax({
                        type:'GET',
                        url:'getSomethingOne.php',
                        data: {
                            'SomethingOneInFirstFunction':one,
                            'SomethingTwoInFirstFunction':two
                        },
                       
                        success:function(data){
                            
                $('.result').html(data);

                                         },
        
            });
            
            $('.result').scroll(function(){
   

                                  alert("Hello! to the first box!!");

            });
            
        }

        function secondFunction(){
    
          var one = '<?php echo $someValueOne; ?>';
          var two = '<?php echo $someValueTwo; ?>';   
                
                    $.ajax({
                        type:'GET',
                        url:'getSomethingTwo.php',
                        data: {
                            'SomethingOneInSecondFunction':one,
                            'SomethingTwoInSecondFunction':two
                        },
                       
                        success:function(data){
                            
                $('.result').html(data);

                                         },
        
            });
            
            $('.result').scroll(function(){
   

                                  alert("Hello! to the second box!!");

            });
            
        }
</script>

even if you will try without the ajax call and only with on click function its will continue the first clicked function scroll call,

how can i stop this?...

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You should set your listener for one-time usage. The problem is that you are setting a new scroll handler for the same HTML element on every call of your function and they are never removed.

$('.result').one('scroll', function() {...})
about 4 years ago · Juan Pablo Isaza Denunciar

0

i was added to the start of each function

$(".result").unbind();

thank you epascarello

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda