I'm going insane. Take a look at this fiddle: http://jsfiddle.net/ndH9G/4/
It's the relevant code from a Rails site I'm working on (for fantasy football). Every time the "type" select is changed, I want to reset the "Direction" select to "Select" to cut down on the wonkiness that happens if the type is changed after the fields are filled in.
Except I can't.
No matter what I do, I cannot access that stupid "Direction" select. If you look, you'll see these two lines:
$('div', location).next('.player-trade-fields').hide();
$('div', location).next('.terms-field').show();
And coming as a shock to no one: those work exactly as they should without issue. But when I try to access the "Direction" select which is at the same DOM level as those two fields:
$('div', location).next('.trade-direction')
I get nothing. I have the alert in there to show me if a value is being returned and absolutely nothing I do returns a value. I don't get it. I don't get how jQuery just will not find it. I've tried:
location.next
selectBox.next
$('div', selectBox).next
$('div', selectBox.parent()).next
$('div', selectBox.parent().parent()).next
$('div', selectBox.parent().parent().parent()).next
$('div', selectBox.parent().parent().parent().parent()).next
Nothing works. I cannot get that select no matter what I do and after 2 hours of time completely wasted on something that, as far as I can tell, should be working without issue much like the code for the fields at the same level is, I give up.
Please show me whatever the obvious thing I've overlooked is.
Figured it out. I changed it to:
$('div', location).find('.trade-direction')
And it's working exactly as it should be and isn't interfering when there are multiple instances of this form on the page added through ajax.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments