Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
190
rated 0 times [  191] [ 1]  / answers: 1 / hits: 38604  / 12 Years ago, tue, august 14, 2012, 12:00:00

I have got this checkbox which has value 1.



<input type=checkbox name=option_1 id=checkbox_1 value=1>


Also I use this method to make checked/unchecked it.



$('input[id^=checkbox_]').not('#checkbox_all').click(function () {
$('#checkbox_all').prop('checked', false);

// Get 'VALUE' of the checkbox here

});


What I need is somehow get 'VALUE' of the clicked checkbox. So In that case it should be 1.



Any clue how do it could be done?



Thank you!


More From » jquery

 Answers
9

In your click method use this to get the value



$(this).attr(value);


$(this) is referencing to the object that has been clicked.



EDIT:
you could also use $(this).val(); but sometimes I had problems with elder versions of IE so I did recommend $(this).attr(value) in the first place.


[#83651] Monday, August 13, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
allans

Total Points: 336
Total Questions: 120
Total Answers: 119

Location: Peru
Member since Mon, Jun 6, 2022
2 Years ago
;