2

I need to find an DropDownList with class addressControlCountry. How?

<div id="myDiv">
 <asp:DropDownList runat="server"  CssClass="addressControlCountry" />
</div>

This doesn't work

$('#myDiv .addressControlCountry')
3
  • Where is the asp tag? shouldn't it be #myDiv? Commented Jul 19, 2011 at 7:57
  • 2
    You're asking a question about client side script but showing your server side code, would be much more useful if you posted the html that is generated when you visit the page. Commented Jul 19, 2011 at 8:01
  • 1
    why don't you check the generated html source? Commented Jul 19, 2011 at 8:01

5 Answers 5

14

Try this

$('#myDiv').find('.addressControlCountry');
Sign up to request clarification or add additional context in comments.

Comments

3

What you already have should work, in theory. However, you could try one of the following:

$('#myDiv').children('.addressControlCountry')
$('#myDiv > .addressControlCountry')

Comments

3

Please use this

$('#myDiv > .addressControlCountry')

3 Comments

What difference would it make for it to work, if the other ancestor descendants didn't work. If the element was the direct child of myDiv, obviously it should have worked already, like it is.
Basically $('#myDiv .addressControlCountry') will search for an element having id="myDiv" and class="addressControlCountry" which is not the case. So we have to define that is should look to its descendants for provided class name.
Wrong! $('#myDiv.addressControlCountry') will search for that.
1

You can use

$('#divLegalAddress).children()

If divLegalAddress has more than one children you may use .eq()-function to pick the right one.

Comments

1

You can scope by the outer div and then select the inner dropdown element as given below

$('.addressControlCountry','#myDiv')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.