I have several <button>
elements on a page, and I need to associate the <input>
elements nearest them to those buttons. Right now, when you hit ENTER
on any input field, it fires the first <button>
in the form. How do I change this?
DOM:
<form action="irrelevant">
<div>
<select><option>1</option><option>2</option><option>3</option></select>
<input type='text'/>
<button>Hello</button>
</div>
<div>
<select><option>1</option><option>2</option><option>3</option></select>
<input type='text'/>
<button>Hello</button>
</div>
<div>
<select><option>1</option><option>2</option><option>3</option></select>
<input type='text'/>
<button>Hello</button>
</div>
<div>
<select><option>1</option><option>2</option><option>3</option></select>
<input type='text'/>
<button>Hello</button>
</div>
</form>
DOM Ready:
$('button').click( function(){
$(this).siblings().filter('select').val('3');
return false;
});