I am using jquery 1.6.2.
Basically in one of my pages, I have a structure that looks like:
<div id="section1">
<fieldset>
<ul>
<li>
<input type="radio" name="1" value="">blah 1</input></li>
<li>
<input type="radio" name="1" value="" checked="checked">
blah 2</input>
</li>
<li>
<input type="radio" name="1" value="">blah 3</input>
</li>
</ul>
<div>
....snipped...
<button type='submit' id='button1'/>
</div>
</fieldset>
</div>
And because I have 100 such structures; I have the equivalent 100 event click handlers of this sort:
var name = "1";
$('#button1')
.parent().parent()
.find("input:radio[name='" + name + "']")
.filter(':checked')
.attr('value');
Is there a way to simplify this with one event listener ?
Typically, with jQuery, you’d use
.live()or.delegate()to reduce the number of event listeners.