using jquery on content page load in asp.net 4.0

3.7k views Asked by At

im beginner in jquery, i need to horizontal accordion menu by using jquery, i found couple of code but i cant use them within master page and content page in asp.net 4.0. how can i define jquery method in asp.net masterpage and content page....here is the jquery sample i wanna use in my page...

contentpage header

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <link href="slidemenu.css" rel="stylesheet" type="text/css" />
<script src="slidemenu.js" type="text/javascript"></script>

endcontent header

maincontent

<script type="text/javascript">
    $('#MainContent').load(Function(){
    slideMenu.build('sm',200,10,10,1);
    });
</script>

here is ul and li tags withi

endmaincontent

2

There are 2 answers

1
Mikhail On BEST ANSWER

To ensure that the DOM hierarchy is fully constructed and the #MainContent element exists, call the required jQuery script within the $(document).ready function:

<script type="text/javascript">
$(document).ready(function() {
    $('#MainContent').load(Function(){
        slideMenu.build('sm',200,10,10,1);
    });
});
</script>

.ready() - jQuery API

1
Ryan On

try moving the script tag into your content page.