I use divs as radio buttons and ask a question.
I declare a function and a variable like this
I have two styles installed: .buttonUp and .buttonDown, which will be applied to the onclick div 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 a 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 it's hard for me to set the default value for the onCheck variable.
I tried to provide an id div, but when I alert($('#Yes') displays [object Object] , whereas if I alert(param_ElementRef) displays [object HtmlDivElement]
Obviously, there is a difference between the two, and is there a way to return the same object via an id or similar link?
Many thanks
source share