tags:

views:

304

answers:

3

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.

+1  A: 

$('.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:

CMS
+1  A: 

Use "this" in your click callback:

$("div.nameofclass").click(function(){$(this).css('border', '1px solid red')});

thedz
A: 

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!

gacon
Thank you CMS very much you are so kind to response me almost imediaterly! I found another way to get its value like that:<br>FriendType = $("td input:radio:checked",$(this)).val();repeater control render my radiobuttonlist in a table with id so I use this code and it run.
gacon
by the way can you show me the way to write code with highlight color like you. I don''t know how to do it.
gacon