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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:52:45+00:00 2026-06-12T09:52:45+00:00

I have a interface that uses the click attribute of a checkbox to show/hide

  • 0

I have a interface that uses the click attribute of a checkbox to show/hide a div.

This is an example chunk of code to show or hide a feature:

Display/Hide jQuery Code

/* Only display LinkedIn sortable icon if "Display LinkedIn" is ticked */
$('#display_linkedin_icon').live("click", function() {
    if ($('#display_linkedin_icon').prop("checked")) {
        $('#LinkedIn').show();
    }
    else {
        $('#LinkedIn').hide();
    }
});

This works great, however I want to change out the normal checkboxes for some fancy jQuery styled checkbox. I want the same jQuery action to still be fired when the fancy checkbox is checked. The checkboxes are simular to the jQuery iPhone checkboxes.

This is the jQuery code for the fancy checkboxes.

Fancy Checkbox jQuery Code

$('.asw-switch-link a').live('click',function(){
    var $tag = $(this).parent();
    $('a',$tag).toggleClass('active');
    var rel = $('a.active',$tag).attr('rel');
    $tag.next('.plugin-switch-value').val(rel);

    return false;
});

and to display them I use:

case 'fancycheckbox':
        echo '<div class="asw-switch-link">';
        echo '<a href="#" rel="true" class="link-true ';
        echo esc_attr($options[$id]) == 'true' ? 'active' : '' ;
        echo '"></a>';
        echo '<a href="#" rel="false" class="link-false ';
        echo esc_attr($options[$id]) == 'false' ? 'active' : '' ;
        echo '"></a></div>';
        echo '<input id="'.$id.'" name="'.$this->prefix.'_options['.$id.']" class="plugin-switch-value" type="hidden" value="'.esc_attr($options[$id]).'" />';

        if($desc != '')
            echo '<span class="description">'.$desc.'</span>';

        break;

The above code is part of a WordPress plugin I am developing.

The issue

The issue is that I have now changed the normal checkboxes to the fancy checkboxes so the jQuery “click” function does not work any more.

From looking at the fancy checkbox jQuery code I thought I might have to check for the CSS class “active” using the JQuery hasclass() function instead of the .prop(‘checked”) function

I thought something like this might work

/* Only display LinkedIn sortable icon if "Display LinkedIn" is ticked */
$('#display_linkedin_icon').live("click", function() {
    if ($('#display_linkedin_icon').hasclass("active")) {
        $('#LinkedIn').show();
    }
    else {
        $('#LinkedIn').hide();
    }
});

but it doesn’t work.

Any help would be greatly appreciated

HTML Code

This is the HTML source code for the LinkedIn checkbox

    <label for="display_linkedin_icon">Display LinkedIn icon?</label></th>
    <div class="asw-switch-link"><a href="#" rel="true" class="link-true active"></a><a href="#" rel="false" class="link-false "></a></div>
    <input id="display_linkedin_icon" name="asw_options[display_linkedin_icon]" class="plugin-switch-value" type="hidden" value="true" />
<span class="description">URL will be the blog article URL or page URL.</span>

The toggled #LinkedIn div

<ul id="asw-sortable">
<li id="Delicious"><span class="sortable-Delicious"></span><span class="sn">Delicious</span></li>
<li id="Twitter"><span class="sortable-Twitter"></span><span class="sn">Twitter</span></li>
<li id="Facebook"><span class="sortable-Facebook"></span><span class="sn">Facebook</span></li>
<li id="Googleplus"><span class="sortable-Googleplus"></span><span class="sn">Googleplus</span></li>
<li id="Stumbleupon"><span class="sortable-Stumbleupon"></span><span class="sn">Stumbleupon</span></li>
<li id="Pinterest"><span class="sortable-Pinterest"></span><span class="sn">Pinterest</span></li>
<li id="LinkedIn"><span class="sortable-LinkedIn"></span><span class="sn">LinkedIn</span></li>
<li id="Youtube"><span class="sortable-Youtube"></span><span class="sn">Youtube</span></li>

The above code is part of a sortable section. I included all the icons so you can see that once I figure this out for the LinkedIn icon I duplicate the code for the other icons.

Update

OK, so far I have got the #LinkedIn div to show on page load by checking for the hidden form field value. If the hidden field is set to ‘true’ the #LinkedIn div will be displayed.

jQuery to display #LinkedIn on page load if value = ‘true’

$('#LinkedIn').hide();
if ($('#display_linkedin_icon').val() == 'true') {
    $('#LinkedIn').show();
}

I still cannot get the #LinkedIn div to toggle though depending on what the value of the fancy checkbox is.

Have tried this function to toggle the #LinkedIn div

   $('#ch_display_linkedin_icon').click(function() {
        $('#LinkedIn').toggle( $(this).toggleClass('active').hasClass('active') );
    if ($('#ch_display_linkedin_icon').hasClass('active')) {
        $('#LinkedIn').hide();
    }
    else {
        $('#LinkedIn').show();
    }
});

I have added an ID to the fancy checkbox.
This above jQuery DOES start to toggle the #LinkedIn div however not always in the correct order. Almost there

  • 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-12T09:52:47+00:00Added an answer on June 12, 2026 at 9:52 am

    Not to oversimplify but this should work fine:

    $('#display_linkedin_icon').click(function() {
        $('#LinkedIn').toggle( $(this).toggleClass('active').hasClass('active') );
    });
    

    I use the non-deprecated .on() vs .live().

    I toggle the active class on the clicked element.

    Last I toggle #LinkedIn based of the clicked element .hasClass().

    Poetry.

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

Sidebar

Related Questions

I have an Asp.Net 4.0 website/control interface that uses an update panel and some
I have a WCF error handler that uses the IErrorHandler interface. In the HandleError
I have an application that uses plugins that are managed via an interface I
I have a fairly large application that uses WPF for its user interface. I
I have been assigned to implement an interface to an API that uses XML
I have a cocoa interface that uses core plot. When I press a button
I am working on a project that uses a touch-screen interface. I have a
I have a C interface that looks like this (simplified): extern bool Operation(void **
I'm working on a site that uses this specific jQuery tab interface: http://www.queness.com/post/106/jquery-tabbed-interfacetabbed-structure-menu-tutorial I
I have an interface that has a generic method with two type parameters. I

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.