0

On the aspx page, I have something like this:

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">   
<script type="text/javascript">
    $("li").mouseover(function () {
        $("li").css("background-color", "blue");
    });
</script>

<ul id="second"> 
<li> <a href.../a> </li>
<li> <a href.../a> </li>
<ul>

and on the masterpage there is a menubar created in the list format too. So when I mouseover the menubar the li background items turn blue, no problem. But when I mouseover the second li nothing happens. I'm not very familiar with asp. I tried the solution JQuery don’t work in aspx-page with Masterpage i'm not even sure if it applies to it.

thanks

Community
  • 1
  • 1
user12345
  • 145
  • 1
  • 2
  • 8

1 Answers1

1

Wrap your code in a document ready event like this...

$(document).ready(function () {
    $("ul.second").delegate("li", "mouseover", function () {
        $("li").css("background-color", "blue");
    });
});

And you can also use the delegate function, which will capture mouseovers on list items even if they are added after your register the event handler.

PS. put this JavaScript in the bottom of your page. This makes your page renders faster.

Split Your Infinity
  • 4,159
  • 1
  • 21
  • 19
  • I consistently use jQuery just like this on my aspx pages, and it should work just as @Bart has described inside your asp:Content like you have it. I have also ran into odd problems with the way I end the functions in relation to where the script end tag is, so check your generated html source to make sure its being recognized properly by the browser – e wagness Jul 13 '12 at 17:37