Accessing the value of a button when it's clicked using jQuery is pretty 
straightforward:

$('.btn').on("click", function(){
    var value = $(this).text();
    console.log(value);
});

This will just print the value of the button when it's clicked, or you can 
do whatever you want with it.

JSFiddle here: http://jsfiddle.net/su4Pq/1/, including method to grab the 
element node itself. Not sure what you're trying to do as a result, but if 
you want the element when you click it then just return the element node.

On Wednesday, 4 July 2012 12:53:40 UTC+1, Barry vd. Heuvel wrote:
>
> If you call the onClick on that element, can't you just detect on what 
> element the event is called?
>
> On Wed, Jul 4, 2012 at 1:39 PM, David Glass <[email protected]>wrote:
>
>> Guys, I just want to chimb in because I'm seeing this being thrown around 
>> as the answer everywhere.
>>
>>  The problem with this solution is when you want to access the value 
>> during the onclick event. The problem I've run into, and can't seem to find 
>> a solution for, is that the "active" class is applied after the click, 
>> which means if you try to get the element for which the "active" class is 
>> applied, you'll basically end up with the previously selected value.
>>
>> Has anyone can find a solution for this?2
>>
>>
>> On Saturday, March 10, 2012 9:00:28 AM UTC-5, djazzmusic wrote:
>>>
>>> noob question really,
>>>
>>> but how do I access the value of the selected radio box ?
>>>
>>> Im trying to make somethin once you click the compose to pick the value 
>>> of the radio box.
>>>
>>> cheers
>>>
>>> ---
>>>
>>>  <script type="text/javascript">
>>> $(document).ready(function(){
>>>   $("#compose").click(function()**{
>>>     $("#message").html('value of the radio box');
>>>   });
>>> });
>>> </script>
>>>  
>>>   </head>
>>>   <body>
>>>   
>>> <div class="container">
>>> <button id="compose" class="btn">compose</button>
>>>
>>> <div id="message">
>>> </div>
>>>
>>>
>>>    1. <div class="btn-group" data-toggle="buttons-radio"> 
>>>    2. <button class="btn">Left</button> 
>>>    3. <button class="btn">Middle</button> 
>>>    4. <button class="btn">Right</button> 
>>>    5. </div>
>>>
>>>
>

Reply via email to