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 1115219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T03:07:31+00:00 2026-05-17T03:07:31+00:00

I can’t show a live example at this point, but i don’t see how

  • 0

I can’t show a live example at this point, but i don’t see how the slideToggle is being called twice. it is called on click of a link.

here:

// initialize the jquery code
 $(function(){
  $('div.slideToggle a').click(function(){
   $(this).parent().siblings('div.remaining-comments').slideToggle('slow',function(){ //'this' becomes the remaining-comments.
    var hidden = $(this).siblings('div.slideToggle').find('input').val();
    if($(this).siblings('div.slideToggle').find('a').html().substr(0,4) == 'Show'){
     $(this).siblings('div.slideToggle').find('a').html('Hide comments');
    }
    else {
     $(this).siblings('div.slideToggle').find('a').html(hidden);
    }
   });
  });
 });

it is meant to display and hide extra comments on a blog page.
however, it is displaying and then hiding in one click. I have put an alert in both the ‘if’ and ‘else’ and both appear, so how is it invoked twice?

obviously when the link contains the text ‘Show’ it reveals the hidden div, and when clicked again it will not find ‘Show’ and will therefore hide the div. The funny thing is, it was working absolutely perfectly. It’s on the company intranet so i suppose maybe something else could be affecting it, but i really don’t see how.

  • 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-05-17T03:07:31+00:00Added an answer on May 17, 2026 at 3:07 am

    It is possible that your document ready is called more than once, when page reinitializes,
    best thing to do is to unbind the click event before binding a new one to it.

    this way you avoid having the click event bound twice on 1 element

    try this:

    $('div.slideToggle a').unbind('click').click(function(){
      // your code here
    });
    

    UPDATE:

    The problem with this above situation is that you have to bind it again to every extra element that is added after you bound the click function the first time.

    You can fix this issue, by binding 1 click handler on a parent item that stays in the dom. Giving it a sub-selector as argument.

    It results in only 1 click handler being added, instead of 1 for each element. So you should win on performance, code execution time, and amount of javascript you were writing.

    example:

    let say you have a list where you dinamically add new elements

    <ul id="ContactList">
        <li>John Doe <a href="#">Like</a></li>
        <li>Jane Doe <a href="#">Like</a></li>
        <li>Josh Doe <a href="#">Like</a></li>
        <li>Jeff Doe <a href="#">Like</a></li>
    </ul>
    

    and you bind some functionality on the anchor tag when it is clicked

    $(function(){
    
        $('#ContactList').on('click', 'li a', function(e){
            // do your thing here...
            var el = $(e.currentTarget);
            el.addClass('iLikeYou');
        });
    
    });
    

    now, no matter how many items you add later on, it will work anyway.
    because it accepts clicks anywhere within the ul#ContactList and will execute the callback only when the clicked element matches the selector li a.

    while $('#ContactList li a') would first get all the elements and then bind the click to all selected items. Newly added items afterwards don’t have the click event and would need to have it bound to them first.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

can someone show me the regex for this preg_match. I want to make sure
Can I order my users in the database, so I don't have to say
Can anyone explain to me why this program: for(float i = -1; i <
Can anyone give me an example of how to return the following json simply
Can I run this in a Windows command prompt like I can run it
Can anybody help me? What should be the datatype for this type -07:00:00 of
Can someone guide me on a possible solution? I don't want to use /bin/cp
can someone explain why the compiler accepts only this code template<typename L, size_t offset,
Can't figure out how to do this in a pretty way : I have
Can someone please explain why this doesn't work? MyClass myClass1 = new MyClass(); object

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.