Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8762081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:26:25+00:00 2026-06-13T15:26:25+00:00

$(document).on(‘click’, ‘#slider_icons_wrapper.play’, function(event) { var slider_icons_wrapper = $(‘#slider_icons_wrapper’); slider_icons_wrapper.attr(‘class’, ‘pause’); autoSlider(cur_img_div_pos); showButton(‘play_icon’); console.log(‘play’); });

  • 0
$(document).on('click', '#slider_icons_wrapper.play', function(event) {
        var slider_icons_wrapper = $('#slider_icons_wrapper');

        slider_icons_wrapper.attr('class', 'pause');
        autoSlider(cur_img_div_pos);
        showButton('play_icon');
        console.log('play');
    });

    $(document).on('click', '#slider_icons_wrapper.pause', function(event) {
        var slider_icons_wrapper = $('#slider_icons_wrapper');

        slider_icons_wrapper.attr('class', 'play');
        clearInterval(inter);
        showButton('pause_icon');
        console.log('pause');
    });

This code works fine for the first time the document is loaded.
When user navigates to another page, via ajax call (document does not refresh), and returns to the page that contains #slider_icons_wrapper div, the function executes twice when user clicks this div. If user navigates again and return, the function executes 3 times and so on!

What am I doing wrong?

Edit#1

When user navigates to another page, element #slider_icons_wrapper is removed from the DOM. When it is injected back via ajax call, the click event is firing on more time, each time. I have tried to unbind the click event when user leaves this page but the same thing happens

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T15:26:26+00:00Added an answer on June 13, 2026 at 3:26 pm

    seems the event listener is being added to the document for every page return. try adding them on document.ready —

    function init(e){
    
        $(document).on('click', '#slider_icons_wrapper.play', function(event) {
            var slider_icons_wrapper = $('#slider_icons_wrapper');
    
            slider_icons_wrapper.attr('class', 'pause');
            autoSlider(cur_img_div_pos);
            showButton('play_icon');
            console.log('play');
        });
    
        $(document).on('click', '#slider_icons_wrapper.pause', function(event) {
            var slider_icons_wrapper = $('#slider_icons_wrapper');
    
            slider_icons_wrapper.attr('class', 'play');
            clearInterval(inter);
            showButton('pause_icon');
            console.log('pause');
        });
    
    }
    
    $(document).ready(init);
    

    user1026361 also makes a good point to remove your listeners before adding them again. however, I believe that using .off( ) without a selector will remove all listeners added to that element via .on( ). if you take the .off( ).on( ) approach I would suggest using a namespace:

    $(document).off('click.clickPlay').on('click.clickPlay', '#slider_icons_wrapper.play', function(event) {
        ...
    });
    
    $(document).off('click.clickPause').on('click.clickPause', '#slider_icons_wrapper.pause', function(event) {
        ...
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

$(document).ready(function () { $(.viewmap).click(function () { var id = $(this).attr(id); var responseURL = ~/changemap?id=
jQuery(document).ready(function(){ var panelContainer = jQuery('div#panels'); jQuery('<div id=tabs></div>').insertBefore(panelContainer); panelContainer.find('div.panel').each(function(n){ jQuery('div#tabs').append('<a class=tab href=#' + (n+1) +
document.click = check; function check(e) { var obj = document.getElementById('calendar_widget'); if (obj != 'null')
document.onmouseover= function(event) { if (event===undefined) event= window.event; var target= 'target' in event? event.target :
$(document).ready(function() { $('#btnAdd').click(function() { var num = $('.clonedInput').length; var newNum = new Number(num +
document.onkeydown = function(event) { var tagName = event.target.tagName; if (tagName != 'INPUT' && tagName
$(document).ready(function(){ $(a).click(function() { $(#content).load($(this).attr(href)); window.location.hash = $(this).attr(href); return false; }); }); So I use
My document.ready: $(document).ready(function () { var apiKey = 58e278fc-9d57-49bb-be96-9e85b847d5b5; $(a#showA).click(function (e) { e.preventDefault(); getHotelInfo(apiKey);
$(document).ready(function(){ $(#submit).click(function() { var name = $(#name).val(); var pass = $(#pass).val(); var image =
$(document).ready(function(){ var var_name=null; $('#id1').click(function(){ $.ajax({ type:GET, url: ggs.erm.servlet.setup5.Page, success:function(response){ var_name=response; console.log(response); } }) });

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.