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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:34:50+00:00 2026-05-16T08:34:50+00:00

I have a FireWorks-generated HTML page and I added some jQuery to it for

  • 0

I have a FireWorks-generated HTML page and I added some jQuery to it for desired effects…it’s for a pain study, so when you click a part of the spine, it lights up in red. I added jQuery’s toggle for sort of an “unclick” option, but it’s not working as expected. (Similar to a previous question I asked, but different enough IMO).

When I click the first time, it does light up red as expected. When I click the second time, it goes back to unclicked, then instantly goes back to red, as though both toggle events were fired, so fast that it’s like the second click didn’t even register (I know it does fire though; I rigged up a pseudo-debug scheme with alerts to make sure the second function was run). Any ideas on what I did wrong?

Here is some relevant code:

jQuery script:

<script type="text/javascript">
$(document).ready(function(){
   $("img.toggle1").click(function(){
      $("img.toggle1").toggle(function(){ 
        alert('first click');
          $(this).attr('src', 'images/cervical_s7.jpg');
      }, function(){ 
          alert('second click');
          $(this).attr('src', 'images/cervical_s1.jpg');
      });
   });
});
</script>

Noteworthy snippets of generated HTML (the table containing the image created by the slice, and the image map created by the slice. I removed the onclick behavior in place of the toggle, and the onMouseOver is for an effect on a different image):

   <td rowspan="2"><img name="cervical_s1" class="toggle1" src="images/cervical_s1.jpg"
    width="185" height="121" border="0" id="cervical_s1" usemap="#m_cervical_s1"
    alt="" /></td>

<map name="m_cervical_s1" id="m_cervical_s1">
<area shape="poly" class="toggleCerv" coords="159,0,154,29,151,57,154,95,165,
       113,185,121,0,121,14,111,23,93,24,43,19,0,48,7,96,7,140,3,159,0,159,0" 
       href="javascript:;  alt="" onmouseover="MM_swapImage
       ('sign_s1','','images/sign_s2.jpg',1);"  /> </map>

tl;dr – jQuery toggle seems to fire twice after the first click so it’s stuck in toggle position #2.

EDIT: When I click again, I get 3 alternating alerts, then 4 alternating alerts, etc. Thanks for the helpful comment. Hopefully this makes it easier to figure out?

Thanks!

  • 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-16T08:34:51+00:00Added an answer on May 16, 2026 at 8:34 am

    Look at http://api.jquery.com/toggle/

    You don’t need to register click().

    So instead of:

    $("img.toggle1").click(function(){
          $("img.toggle1").toggle(...);
       });
    

    Put

    $("img.toggle1").toggle(...);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: <html> <head> <script type=text/javascript language=javascript src=jquery/jquery-1.5.1.js></script> <script type=text/javascript language=javascript
i have added a custom font - one which i have downloaded from from
I have been trying to create a HTML E-mail, which is just one image
I am a systems programmer, so i just know some basic css/html. I like
I'm using this plugin: http://www.fyneworks.com/jquery/star-rating/ Is it possible to put a click function inside
Have some dates in my local Oracle 11g database that are in this format:
I have a Python script that takes in '.html' files removes stop words and
Have started playing with Xcode 4.2, and created a single page application using storyboard
Have a bit of problem with the jQuery clone() functionality. Basically I have a
I have found a pretty stuff for rating entries: http://www.fyneworks.com/jquery/star-rating/ . It's good and

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.