Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

161
Views
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 answers
Answer question

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 Report

0

i was added to the start of each function

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

thank you epascarello

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!