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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:41:55+00:00 2026-05-28T19:41:55+00:00

How can i use Jquery to add a class on user selection? My Aspx

  • 0

How can i use Jquery to add a class on user selection?

My Aspx markup is as follows.

     <div id="Answer" class="Ans">
           <div id ="Left"> 
           <asp:RadioButton ID="rdAnsBool1" runat="server" Text = '<%# DataBinder.Eval(Container.DataItem, "Ans1") %>' />
           <asp:RadioButton ID="rdAnsBool2" runat="server" Text = '<%# DataBinder.Eval(Container.DataItem, "Ans2") %>' />
           <asp:RadioButton ID="rdAnsBool3" runat="server" Text = '<%# DataBinder.Eval(Container.DataItem, "Ans3") %>' />
           <asp:RadioButton ID="rdAnsBool4" runat="server" Text = '<%# DataBinder.Eval(Container.DataItem, "Ans4") %>' />
           <asp:RadioButton ID="rdAnsBool5" runat="server" Text = '<%# DataBinder.Eval(Container.DataItem, "Ans5") %>' />
           <asp:RadioButton ID="rdAnsBool6" runat="server" Text = '<%# DataBinder.Eval(Container.DataItem, "Ans6") %>' />
           <asp:HiddenField ID="HiddenField1" runat="server" Value = '<%# DataBinder.Eval(Container.DataItem, "Ans1Bool") %>'/>
           <asp:HiddenField ID="HiddenField2" runat="server" Value = '<%# DataBinder.Eval(Container.DataItem, "Ans2Bool") %>'/>
           <asp:HiddenField ID="HiddenField3" runat="server" Value = '<%# DataBinder.Eval(Container.DataItem, "Ans3Bool") %>'/>
           <asp:HiddenField ID="HiddenField4" runat="server" Value = '<%# DataBinder.Eval(Container.DataItem, "Ans4Bool") %>'/>
           <asp:HiddenField ID="HiddenField5" runat="server" Value = '<%# DataBinder.Eval(Container.DataItem, "Ans5Bool") %>'/>
           <asp:HiddenField ID="HiddenField6" runat="server" Value = '<%# DataBinder.Eval(Container.DataItem, "Ans6Bool") %>'/>
           </div>
        </div>

The visitor may select the answer by choosing the “winning question” radiobutton

The HiddenFields contain true or false

So if the user selects the rdAnsBool1 and the value of the HiddenField1 is “True”, the JQuery should add a “correct” CSS class to the parent div with ID = Answer

If the user selects the rdAnsBool1 and the value of the HiddenField1 is “False”, the JQuery should add a “wrong” CSS class to the parent div with ID = Answer

In your answers please keep in mind that the following markup is rendered within a list view

And here is the JSFiddle link

http://jsfiddle.net/VTevz/

  • 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-28T19:41:55+00:00Added an answer on May 28, 2026 at 7:41 pm

    Just as an FYI, hidden field values are visible with HTML inspectors so not the best place to store secret answers.

    Assuming your ID’s and names will stay the same (not a very good idea but nonetheless)…

    This works: http://jsfiddle.net/VTevz/6/

    $(function() {
        $('input[name$="answers"]').change(function() {
            // clear all the previous classes
            $('input[name$="answers"]').parent().removeClass('correct').removeClass('wrong');
    
            // get the index of the selected answer
            var i = $('input[name$="answers"]').index(this);
    
            // get the value of the corresponding correct answer
            var answer = $('input[type="hidden"]:eq(' + i + ')').val();
    
            // check if it's true and add the appropriate class
            if (answer == 'True') $(this).parent().addClass('correct');
            else $(this).parent().addClass('wrong');
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I use jquery to remove a SPECIFIC div that has no children
how can i use jQuery to show/hide the same div area... essentially swapping out
Can I use Jquery to call an action and then change the image when
How can I use jQuery to determine whether an element has a certain style
I would like to know how can I use jQuery to select multiple items
I have an image $(#main) how can I use jquery to dosomething(this) when the
It doesn't look like basic javascript but nor can I use JQuery commands like
I have a blob of HTML. How can I use jQuery to remove the
How does collision detection work in JavaScript? I can't use jQuery or gameQuery -
I have a document with headings and unordered lists. How can I use JQuery

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.