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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:33:36+00:00 2026-06-09T09:33:36+00:00

I have a live -on click- event for a Header which has an arrow

  • 0

I have a live -on click- event for a Header which has an arrow flipping up/down upon opening & closing it’s contents.

The strangest thing is happening with ! followed by a variable — which is supposed to flip it from true -> false, and vice versa. Basically it’s not working at all, and it flips to false and stays there… Check out the fiddle to see what I mean.

I’ve deleted lots of code for the sake of brevity.

Demo Code

$(document).on('click', '.regimenHeader', function () {
    var _state = $(this).attr('data-state');

    if (_state === 'true') {
        // do stuff
    }

    else { 
        // do stuff
    }

    // This is where the issue is happening, it isn't flipping the Boolean value
    // !"true" = false, !true = false, it works with strings or booleans
    $(this).attr('data-state', !_state);
});​

I can get it working perfectly fine if I do the following:

    if (_state === 'true') {
        // Manually flip the data-state boolean
        $(this).attr('data-state', false);
    }

Is there something I’m missing why this isn’t working the way it should ?? Just wondering why it’s doing this!

  • 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-09T09:33:37+00:00Added an answer on June 9, 2026 at 9:33 am

    I think you are trying to do this:

    http://jsfiddle.net/JKUJb/2/

    if so, the problem was that you are using .attr() which returns a string, so if you convert:

    !"true" //false
    
    !"false" //false
    

    .data() on the other hand returns the value already “casted

    EDIT:

    Just to be more clear, in javascript the only falsy values are:

    false;
    null;
    undefined;
    '';
    0;
    NaN;
    

    So if you really wanted to use .attr(), you could, but I recommend that first you do:

    var _state = $(this).attr('data-state') === 'true'; //if 'true' then true, false otherwise
    

    Good luck!

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

Sidebar

Related Questions

I have the following script which works fairly well: $(.btnMinimize).live('click', function(event) { event.preventDefault(); $(
So I have a .live() click event on a textarea which allows user to
I have some functionality which is bound to a click event: $('.addButton').live('click', function(){ //stuff
I have this js code: $(#startSearch).live(click, function(event) { $(input:checkbox[name='searchId']:checked).each(function() { var searchId = $(this).val();
I have a div containing a href. The div has a jQuery live click
I have a jquery event binding using .live that adds fancybox to the click
I have a script that is looking for a live click event, but I
I am loading content into a page with ajax that will have live click
I have the following bit of code, simply: $(function() { $('a.add-photos-link').live('click', function(e) { $(this).colorbox({
I have this function: <script type='text/javascript'> $('#clicktogohome').live('click', function(){ history.pushState({}, '', this.href); popstate(this.href); return false;

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.