user1104980
user1104980

Reputation: 23

Access .aspx div from .ascx using jquery

I am developing an ASP.NET 4.0 webforms application in VS 2010.

I have an .aspx page (A.aspx) with a web control (A.ascx) on it.

Now A.aspx has a div with id="divToggle". I want to be able to use jquery to access the "divToggle" from within A.ascx. I tried using $('#divToggle') and $.find('#divToggle') but both return null. I have no trouble accessing elements this way on the same control/page.

Is there a way I can access A.aspx's "divToggle" from A.ascx in jquery?

Thanks in advance, Tim

Upvotes: 0

Views: 657

Answers (1)

Turch
Turch

Reputation: 1546

Where does the script code get added to the page? If you can't find the element, then the script code is run before the element gets added to the DOM. Try putting the code into .ready():

$(document).ready(function() {  
    // code
});

Upvotes: 1

Related Questions