I have a list of div with the same class name. I wonder how to catch exactly which div client click on it by using jquery. I try many way in many times but I couldn''t figure out. Please help me because I''m newbie in jquery.
$('.myClass').click(function(){ $(this); //This is the clicked div });
Edit: In response to your new question
You can get all the radio button selected doing something like this:
$('input:radio:checked').each(function(){
$(this); // Checked radio button element(s)...
});
There you can access the element value with $(this).val()
, or also the name attribute, with $(this).attr('name')
.
Recommended lecture:
Use "this" in your click callback:
$("div.nameofclass").click(function(){$(this).css('border', '1px solid red')});
Thank you very much CMS and dz. Can you point out to me another my trouble that I want to get selected value of radiobuttonlist in this class. I write it in usercontrol and nested it in a repeater control.
I'm using javascript and it ok but I don't know how to do it in jquery.
My original code in javascript like that:
var list = document.getElementById("_ctl0_cphLeft_Profile_FriendStyleWaitting1_rptFriendWait__ctl" + tt + "_rdbtlFriendType");
var inputs = list.getElementsByTagName("input");
var selected;
for (var j = 0; j < inputs.length; j++)
{
if (inputs[j].checked)
{
selected = inputs[j];
FriendType = selected.value;
break;
}
}
tt is mean the number of which class client click on it. How I transfer it in jquery?
Please help me sold this, thank you a milion times!