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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:51:31+00:00 2026-06-14T18:51:31+00:00

In the pasted code, the ternary code checks for the presence of a checkbox

  • 0

In the pasted code, the ternary code checks for the presence of a checkbox click and displays the result accordingly. The drawback is that if a user unchecks one of the boxes then it hides the checked div. I only need to hide the checked div if no boxes are ticked.

Can my code be adjusted to accommodate this or do I need to rewrite using if statements. Thanks

$(function() {
    $('input[id^=check]').on('click', function() {
        var checked = '';

        $('input:checkbox:checked').each(function (i) {
            checked += this.value + ',';     
        });

        $('.checked').show().html('Checkbox is checked: <strong>' + ($(this).is(':checked') ? checked : $(".checked").hide()) + '</strong>');
    });
});
  • 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-14T18:51:32+00:00Added an answer on June 14, 2026 at 6:51 pm

    Simplest way, whilst keeping your basic layout and logic, I’d say is to change your

    $(this).is(':checked')
    

    to a

    checked.length > 0
    

    Thus only hiding the div if you actually have added values to the checked-string..

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

Sidebar

Related Questions

The code pasted below gets an exception on the line that says... InputStream in
I have pasted some code that looks like this: Dto = new MyDto() {
I have a plot (sample code pasted below) that I am trying to add
For a rich text editor that has to handle pasted HTML code from MS
I copy and pasted some code that increments an enum: myenum++; This code worked
From REST API of twitter I user get/followers function. I pasted a code snippet
I have pasted a code snip below that I have written which reads a
The code pasted below was taken from Javadocs on HttpURLConnection . I get the
The code pasted below is a simple JSF program, with an idea of having
I pasted the code given in this link to a file called md5.js. http://www.webtoolkit.info/javascript-md5.html

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.