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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:43:18+00:00 2026-05-26T19:43:18+00:00

I need to toggle an element ONLY if it is not disabled. jQuery(#sbutton).toggle( function

  • 0

I need to toggle an element ONLY if it is not disabled.

jQuery("#sbutton").toggle(
    function () {
        if (!jQuery(\'input[name^="choose"]\').attr ( "disabled" )) {
            jQuery(\'input[name^="choose"]\').attr ( "checked" , true);
        }
    },
    function () { 
        jQuery(\'input[name^="choose"]\').removeAttr("Checked"); 
    }
)

Is the IF condition possible?

  • 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-26T19:43:18+00:00Added an answer on May 26, 2026 at 7:43 pm

    What you probably want to do (thanks Frédéric):

    jQuery("#sbutton").click(function() {
        if (jQuery('input[name^="choose"]').is(':disabled'))
            return false;
        if (jQuery('input[name^="choose"]').is(':checked'))
            jQuery('input[name^="choose"]').removeAttr("checked");
        else
            jQuery('input[name^="choose"]').attr("checked", true);
    });
    

    or simply

    jQuery("#sbutton").click(function() {
        var checkbox = jQuery('input[name^="choose"]');
        if (checkbox.is(':disabled'))
            return false;
        checkbox.attr('checked', !checkbox.is(':checked'));
    });
    

    The problem with your code is that you expect the evaluation on disabled to be evaluated on every button click and use the first function if true. It’s only called on every other click though, and the other function doesn’t care if it’s disabled or not. It checks the check box no matter what. You have to either bind on the click event, like I’ve done, or bind to and unbind from the toggle event depending on whether or not the button is disabled.

    In the future it would be easier to help you if you present your code as a fiddle (http://www.jsfiddle.net) and describe more thoroughly what you’re trying to do and what it is that’s not working.

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

Sidebar

Related Questions

Please I need to apply the toggle() function to only li that has ul
Need a function that takes a character as a parameter and returns true if
Need a function like: function isGoogleURL(url) { ... } that returns true iff URL
I need to toggle a div on click of an element within that div.
I have some JQuery Code as follows: $(#sh-zone-button-cart-menu).live(click, function(event) { event.preventDefault(); $(#sh-zone-cart-menu).toggle(0, function(){ if($(this).is(:visible)){
I used this function to animate the parent element of the link: $(.user-review-toggle).toggle(function(){ $(this).css(backgroundPosition,
I have a case where I need to toggle the visibility of an element
I have some HTML that I need to toggle between two structures - one
Need to an expression that returns only things with an I followed by either
Need to call a filter function on some options based on a radio selected

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.