Andrew
Andrew

Reputation: 2839

jQuery asp:Menu link replacement

I have an control that has a horizontal layout, and is supplied data by an XML file based on the user. When I run launch the page from localhost, the mouseover on the HOME node gets replaced by the jQuery script. When I click on another node in the menu, the page renders (postback), but the script does not replace the HREF on the Home menu node.

The source of the Menu control renders like this:

<ul class="level1">
<li>
<a class="level1" href="#" onclick="__doPostBack(&#39;ctl00$Menu1&#39;,&#39;Home&#39;)">Home</a></li>
<li><a class="level2" href="default.aspx">Sales</a><ul class="level3">

I have the following script in my ASPX page.

<script src="Scripts/jquery-latest.js" type="text/javascript"></script>
<script type="text/javascript">
    $(function () {
               $('.level1').attr('href', 'http://www.google.com')
      });
</script>

How to I get the script to fire off on each click of the menu?

** I understand this might be a hacky solution. A sitemap file doesn't suit my purpose, so I'm trying to get around the limitation of not being able to set the URL on the top node of the menu (https://stackoverflow.com/questions/19797424/setting-url-of-top-node-in-aspmenu-control).

Upvotes: 0

Views: 210

Answers (0)

Related Questions