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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:58:48+00:00 2026-06-04T13:58:48+00:00

This is my first question here on Stack Overflow. I generally find all my

  • 0

This is my first question here on Stack Overflow. I generally find all my answers from searching but I’m completely out of motivation after writing the following code.

Is there a more efficient way or short-hand to write the following code?

Currently it does exactly what I want. When you click a radio button a div is loaded next to that radio button. If you switch the radio button it removes the div and creates a new one next to that radio button.

I’m fairly new to actually writing my own JavaScript/jQuery. I know about CASE but I’m not entirely sure if this is a good situation for that.

Any suggestions would be greatly appreciated.

 jQuery(document).ready(function($) {

var checkedItem = true;

$('form input').click(function(){

    if (checkedItem == true){
        $(this).siblings('div.next').remove('.checked');
        $(this).after('<div class="next">NEXT</div>');
        $(this).siblings('div.next').addClass('checked');

        checkedItem = false;

    }
    else {
        $(this).siblings('div.next').remove('.checked');
        $(this).after('<div class="next">NEXT</div>');
        $(this).siblings('div.next').addClass('checked');

        checkedItem = true;     
    }

});

 });


    <form id="input-form">
<input class="PAD" type="radio" name="Seasons" value="Spring-Fall" /> Spring-Fall<br />
<input class="PAD" type="radio" name="Seasons" value="Winter" /> Winter
</form> 
  • 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-04T13:58:49+00:00Added an answer on June 4, 2026 at 1:58 pm

    If you’re on jQuery 1.7+ you can:

    HTML

    <form id="input-form">
        <input class="PAD" type="radio" name="Seasons" value="Spring-Fall" /> 
        Spring-Fall<br />
        <input class="PAD" type="radio" name="Seasons" value="Winter" /> Winter
    </form>
    

    jQuery

    $(function() {
        $("input[type=radio]").click(function() {
            if ($(this).is(":checked")) {
                $(this).siblings('.next').remove('.checked');
                $(this).after('<div class="next">NEXT</div>');
                $(this).siblings('.next').addClass('checked');
            }
            else { // fyi, this, or your var is kinda useless redundancy, but just for purpose of show, here ya go
                $(this).siblings('.next').remove('.checked');
                $(this).after('<div class="next">NEXT</div>');
                $(this).siblings('.next').addClass('checked');
            };
        });
    });
    

    Although you could easily simplify the whole thing with:

    $(function() {
        $("input[type=radio]").click(function() {
            $(this).siblings('.next').remove();
            $(this).after($("<div />").addClass("next checked").text("NEXT"));
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my first question here. I have been searching Stack Overflow and other
This is my first question here on stack overflow. i need help on a
this is my first question here at Stack Overflow. I've been looking for a
This is probably the dumbest question ever here on stack Overflow. But I am
This is the first time i'm asking a question here at stack overflow so
first of all this is my third question about web services here and i
this is my first question on stack overflow, so be gentle. Let me first
This is probably the worst question I have ever posted on Stack Overflow but
First of all excuse me for my english. This is my first question here.
this is my first question on Stack Overflow. This is not really a programming

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.