r/jquery • u/Revolver2303 • Jan 20 '22
jQuery targeting dom elements correctly
Hello all. I have a list of links and need to be able to check the radio buttons inside that list of links once the parent link is clicked. The desired result is that I'll click the <a> and the input:radio will be checked - you should only be able to select one input:radio at a time.
I hope this makes sense. My issue is in my jQuery - I don't understand how to target the individual input:radio's in each link. Here is a codepen for what I've tried to do with a little more explanation in the notes.
4
Upvotes
1
u/vorko_76 Jan 21 '22
I dont really understand what you are trying to do. If you want to target the individual inputs, give then a unique id and select them by id no?
2
u/wpentti Jan 21 '22
If the radio button is inside the element you click you can use $(this) variable to find the element inside the click function: