<span>
<img src="img/icon.png" alt="" />
<label><input type="radio" name="" /> Label here</label>
</span>
I want the whole <span>
to be clickable, not just the radio input. How do I do it with jQuery?
<span>
<img src="img/icon.png" alt="" />
<label><input type="radio" name="" /> Label here</label>
</span>
I want the whole <span>
to be clickable, not just the radio input. How do I do it with jQuery?
This is a better way.
Just keep in mind that you are adding a click event to all spans. Better would be to have a class on the span and reference that.
It looks like you're not using the
for
attribute of the label. Maybe doing so will help youYou could do it without jQuery by just making the
<span>
the<label>
instead:I believe should do it.
Well, the easiest solution would be to wrap everything inside the
<label>
tag, like this:When you specify an
for
attribute to label, and the sameid
to the field, the label becomes clickable and will activate the corresponding input.But, if you for some reason need to do it in jQuery, this should work: