1252748
1252748

Reputation: 15369

select a dropdown with a class within a parent div

I'm trying to use jquery to select a select menu that is under a parent div. I keep getting nothing returned though.

$('#content_container > .vendor_address_select');

what is incorrect here?

Thanks!

Upvotes: 1

Views: 1117

Answers (4)

Blake Plumb
Blake Plumb

Reputation: 7209

$('#content_container .vendor_address_select');

You don't need to have the greater than sign. This will apply to all the descendants of content_container with the class of vendor_address_select

This method is using jQuery Descendant Selector (“ancestor descendant”). It is referenced here in the docs.

Mad Echet has a great point that > means that .vendor_adress_select is a child of #content_container

Upvotes: 2

Jai
Jai

Reputation: 74738

use this to find any children in the parent element:

$('#content_container').find('.vendor_address_select');

this will find children element at any level. cheout the fiddle: http://jsfiddle.net/xdC6T/

Upvotes: 0

Try targeting your element more directly. You shouldn't need to use a combinator. Also, are you by chance mixing .js scripts (prototype.js with jQuery.js?) If you are mixing scripts, you may need to use jQuery's No Conflict rule.

Try this though:

$(".vendor_address_select")

Upvotes: 0

Mad Echet
Mad Echet

Reputation: 3881

You should post the HTML but the > means the .vendor_adress_select is a direct child of #content_container so if it is a grand-child you will not receive anything in response.

Upvotes: 2

Related Questions