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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:49:14+00:00 2026-05-25T00:49:14+00:00

I have a span element that replaces a checkbox so I can style it.

  • 0

I have a span element that replaces a checkbox so I can style it. I also have a label tag; when clicked it should fire the span’s click event as if the user has just clicked the span element. In other words – I’m mimicking the label/checkbox relationship with label/span.

This functionality works as intended in Firefox and Chrome but not IE. In IE 7 and 8, clicking the label does nothing and seems to generate some odd attribute in the source:

<span class="checkbox" id="Vechicle-1" jQuery15105041923284548672="2"/>
<label class="large text-left" for="Vechicle-1" jQuery15105041923284548672="24">

In IE 9 I do not see the jQuery string appended and 2x clicking the label will fire off the span’s click event.

$('.checkbox').click(function () {
    $(this).toggleClass('checked');

    if ($(this).hasClass('checked')) {
        $('#checkbox-' + $(this).attr('id')).attr('checked', 'checked');
    } else {
        $('#checkbox-' + $(this).attr('id')).removeAttr('checked');
    }
});

$('label').click(function () {
    $('#' + $(this).attr('for')).click();
});

Any idea what’s causing this behavior?

  • 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-25T00:49:15+00:00Added an answer on May 25, 2026 at 12:49 am

    Maybe the click event is bubbling upwards and trigger some other code you might have, try to prevent it by changing the code to:

    $('.checkbox').click(function (event) {
        event.preventDefault();
        $(this).toggleClass('checked');
        //......
    

    And the same for the other click handler.

    Edit: found the root of this behaviour. As it turns out, IE browser “let” label affect non form elements as well, including <span> meaning that clicking label element will trigger the click event of the element having ID defined as the label for attribute – no matter what is the element type.

    Chrome (and probably Firefox) would let it trigger only form elements like checkbox, as expected.

    Proof of this can be found here just browse with IE browser (even 9) and see the span is “clicked” when label is clicked even though the jQuery line is commented.
    (Code in fiddle is the same as in the original question)

    All this boils down to the interesting conclusion: clicking the label caused the span to be clicked twice – one time by the browser and another by jQuery code, causing it to toggle its state twice.

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

Sidebar

Related Questions

I have a span element that I want to become editable upon double-click. (That
I have a span element inside a table td element. The span tag has
I have a container with a span tag and if I click the span
I have span element <span class=tag onclick=clickTag(this) tagType=property> Which calls the clickTag method function
I have a function that creates a span element with a removeme class and
I have an element that I need so span across the whole screen. It
I have two span elements that I would like to stay on the same
I have an element like this: <span class=tool_tip title=The full title>The ful&#8230;</span> This seems
I have WPF Span that is used as a source to a TextBlock. I
I have a span with the following style: margin: 5px 0; padding: 2px; cursor:

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.