Can't find DOM element in jQuery

Kyle K

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.

Kyle K

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

jQuery: "this" can't find element generated by .html()

From Dev

Backbone Marionette LayoutView can't find DOM element

From Dev

Can't find the id of parent element of clicked element using jquery

From Dev

Can't get to the DOM element

From Dev

Can't add element to DOM

From Dev

Jquery can't find element after ajax call

From Dev

Why can't jQuery find this react.js element?

From Dev

Find previous DOM element jquery using this

From Dev

Jquery find string in DOM and get his element

From Dev

Selenium can't find element

From Dev

Javascript: can't find element

From Dev

Can't find element in frame

From Dev

Can't find element in frame

From Dev

Can't find an element by "querySelector"

From Dev

Can't find elements of element

From Dev

Why I can't retrieve and print the tag name of an element retrieved from my DOM in this JQuery script?

From Dev

jQuery ajax post using FormData() append data element can't find the appended data element after post

From Dev

can't find DOM index of blurred object

From Dev

I can't change dom from dom element stored as an attribute

From Dev

angularjs can't find "this" by jQuery?

From Dev

angularjs can't find "this" by jQuery?

From Java

Why does jQuery or a DOM method such as getElementById not find the element?

From Dev

Snap.svg can't find dynamically (and successfully) appended SVG element with jQuery

From Dev

Jquery index() doesn't find my element

From Dev

IndexOf can't find last element in a List

From Dev

why can't find/parse this element in HTML?

From Dev

Can't find specific element in LinkedListNode

From Dev

Selenium IDE can't find an element

From Dev

Can't find an element Selenium Python

Related Related

HotTag

Archive