0

I am trying to add "active" class by jQuery because that code from a aspx master file. I know PHP but no ASAP.

When anyone go to submenu page like Technical-Info.aspx, End-Device-Info.aspx page then need addClass on parent li(<li class="active"><a href="OverView.aspx" title="Overview">OverView</a> instead of <li><a href="OverView.aspx" title="Overview">OverView</a>).

Code-

<ol id="menu">
         <li><a href="Default.aspx" title="Home Page" style="color:#FFF">Home</a>        
        <li><a href="OverView.aspx" title="Overview">OverView</a>  

          <!-- sub menu -->
          <ol>     
            <li><a href="Technical-Info.aspx" title="Technical Info">Technical Info</a></li>
            <li><a href="End-Device-Info.aspx" title="End Device Info">End Device Info</a></li>
          </ol>
        </li><!-- end sub menu -->

        <li><a href="Register.aspx">Register To Service</a></li>
        <li><a href="Rates.aspx">Rates</a></li>

        <li><a href="#">Support</a>

          <!-- sub menu -->
          <ol>     
            <li><a href="FAQ.aspx" title="FAQ">FAQ</a></li>
            <li><a href="TOS.aspx" title="TOS">Terms Of Service</a></li>
            <li><a href="Contact_Us.aspx" title="Order the service">Contact Us</a></li>
          </ol>
        </li><!-- end sub menu -->

         <li><a href="skype:name?call" title="Call us on Skype"><img src="img/callme_small4.png" width="85px" height="85px"; /></a></li>

</ol>
1
  • To clarify: you have a number of pages. The menu is on each of them, with identical HTML, but you want to do conditional styling for the menu entry that matches the current page? Commented Jul 10, 2014 at 1:10

2 Answers 2

1

You can use following:

$("li[title=FAQ]").addClass("active");
Sign up to request clarification or add additional context in comments.

Comments

0

One alternative is to to these changes in the server side. To do so, you would have to transform each HTML element into a server-side control. To do so, simply put a tag runat="server" in each of them, and put an ID to identify them. For instance:

<li><a href="OverView.aspx" title="Overview">OverView</a></li>

becomes:

<li id="overviewMenu" runat="server"><a href="OverView.aspx" title="Overview">OverView</a></li>.

Then on the server side, use to follow pseudo algorithm:

  1. Retrieve all menus and mark them as not 'active".
  2. Select the menu to be marked and set it as 'active'.

Here are a few methods of ASP.NET which will be useful:

  1. In order to get your HTML controller server-side by id, use the following method: HtmlControl control = (HtmlControl) this.FindControl("controllerId");, where the controllerId is your server side id. You can use the HtmlControl generic type to cast all your HTML controls. You will need the package System.Web.UI.HtmlControls for the HtmlControl.
  2. To add the active class use the following command: control.Attributes.Add("class", "active");. To remove, use this one: control.Attributes.Remove("class");;

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.