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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:23:50+00:00 2026-06-01T15:23:50+00:00

I am using divs like radio buttons and have a question. I declare a

  • 0

I am using divs like radio buttons and have a question.

I declare a function and variable like so

I have two styles set up, a .buttonUp and .buttonDown to be applied upon a div’s onclick event.

<script type="text/javascript">
var onCheck;

function setRadio(param_ElementRef) 
{
    if (param_ElementRef != onCheck) 
    {
        if (onCheck) 
        {
            onCheck.className = 'buttonUp';
        }
        param_ElementRef.className = 'buttonDown';
        onCheck = param_ElementRef;
    }
}
</script>

I call a function in the div like this

<div id="Yes" class="buttonUp" onclick="setRadio(this)">Yes</div>
<div id="No" class="buttonUp" onclick="setRadio(this)">No</div>
<div id="Maybe" class="buttonUp" onclick="setRadio(this)">Maybe</div>

This works fine, but I’m having trouble setting a default value for the onCheck variable.

I have tried giving the divs id’s, but when I alert($('#Yes') it displays [object Object], whereas if I alert(param_ElementRef) it displays [object HtmlDivElement]

There is obviously a difference between the two, and is there a way of returning the same object by id reference or similar?

Many thanks

  • 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-01T15:23:51+00:00Added an answer on June 1, 2026 at 3:23 pm

    The reason alert($('#Yes') displays [object Object] is because it is a jQuery object.

    On the other hand if you want [object HtmlDivElement] to be returned try alert(document.getElementById('Yes')) instead of alert($('#Yes'))

    You can also get the plain js object from a jQuery object by using get()

    for eg.
    alert($(‘#Yes’)) displays [object Object] and if you try alert($('#Yes').get(0)) you will get [object HtmlDivElement]

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

Sidebar

Related Questions

I have multiple divs like setted up below. I want 1 (one) JQuery function
I have a set of divs like so: <div id=textArea> <div id=text></div> </div> CSS
I have two divs like so <div id=parent style=width:100px:overflow:hidden;> <div id=child> tooooooooooooooooooooo much content
I have been working on building my first CSS site using divs and am
We have an HTML page which displays a bunch of pretty bars using divs
I have ASP.Net code generating my button's HTML for me using divs to get
i'm having the following markup using 2 divs. the #child div has set position:absolute;
I have a series of divs like this: <div id=available-posts> <div class=post id=unique_id> <a
I toggle a div using something like this - <input type=radio name=myRadio value=myDiv_1 />MyDiv
I have a page which has DIVs which contain short phrases (one-two words) of

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.