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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:12:01+00:00 2026-06-02T19:12:01+00:00

I have four div with class name .s-list . When the user clicks on

  • 0

I have four div with class name .s-list. When the user clicks on any of those divs .selected class is applied on the div.

What I am trying to do is while clicking on a button, check all those divs and if any one of them has a class .selected submit a form, else if none of the div has a class .selected show a error message.

The problem:
It works for the first time, but again if I click the button it shows the error message and submit the form when the div already has the class selected.

$("#pp-btn").click(function() {

    $(".s-list").each(function (i) {
         if(!$(this).hasClass('selected')) 
         { 
            $("#p-msg").show(); 
         } 
         else { 

            $("#plans-form").attr('action', $(this).attr('links'));

            $("#p-msg").hide();
         }
        });  
    });

I don’t want the message to be displayed if any 1 of the div has class ‘selected’.

Help please…

  • 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-02T19:12:01+00:00Added an answer on June 2, 2026 at 7:12 pm

    Use a jQuery selector to check if any s-list element has a selected class;

    $('#pp-btn').click(function (e) {
    
        if ($('.s-list.selected').length == 0) {
            /* No `selected` class on any `s-list` */
            $('#p-msg').show();
        } else {
            /* At least one `s-list` has the additional `selected` class */
            $('#plans-form').attr('action', $('.s-list.selected').attr('links'));
        }
    
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have four divs contained in another div, and I want the four inner
If i have the following markup; <div id=container> <div id=box> <div id='sameHeight'>One<br>two<br>three</div> <div id='sameHeight'>four</div>
I have four class; UserGroup, UserAccount, Role, UserGroupRoleRelation and my db is IBM DB2
We have many links with rel attributes: <div class=team-tags> <a class=s1 rel=t1 t2 t3
I am setting up a page with jQuery's Cycle plugin and have four divs
I have an input field and a div with four operating systems. When the
I have a series of divs of the same class; some with title attributes
I have four HTML div I want to show and hide them on click
I have a drop down list and 5 divs along with it.I need to
I'm developing a List of four items. Each item needs to have a top

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.