brown2005 Posted May 28, 2009 Share Posted May 28, 2009 hi i have a class .active { } and the menu <ul> <li class='active'>Home<li> <li>Page1<li> <li>Page2<li> </ul> When I select a new page how can I chagne the active part to the appropiate page? Thanks in advance Quote Link to comment Share on other sites More sharing options...
anupamsaha Posted May 28, 2009 Share Posted May 28, 2009 hi i have a class .active { } and the menu <ul> <li class='active'>Home<li> <li>Page1<li> <li>Page2<li> </ul> Thanks in advance Can you please provide some more information here? Quote Link to comment Share on other sites More sharing options...
brown2005 Posted May 28, 2009 Author Share Posted May 28, 2009 what i mean is at the start the menu will be... <ul> <li class='active'>Home<li> <li>Page1<li> <li>Page2<li> </ul> if i click on page1 then it will be <ul> <li>Home<li> <li class='active'>Page1<li> <li>Page2<li> </ul> and so on.... what I want to know is; what can I do to automatically remove the class from one page and put it onto another, when the page is selected. Quote Link to comment Share on other sites More sharing options...
Dathremar Posted May 28, 2009 Share Posted May 28, 2009 Put id on that <li> tags and then use Java Script to put the "active" class on your selected link. For the java script part: document.getelementbyid(id_changed).className = newClass; document.getelementbyid(id_previous).className = ""; // or some other class Also another option is if You reload the page do that with php. Quote Link to comment Share on other sites More sharing options...
anupamsaha Posted May 28, 2009 Share Posted May 28, 2009 Here is the concept in pure PHP. Please try this. commonInclude.php <?php /** * commonInclude.php */ // List of pages $pageArray = array( 'home', 'page1', 'page2', ); function getLink($pageIndex = 0) { global $pageArray; $returnLinks = array(); // Print the starting UL print '<ul>'; // If the pageIndex passed to the function does not exist in $pageArray, take the home as default if ( !isset($pageArray[$pageIndex]) ) { $default = 0; } // Else, default is the pageName passed in this function else { $default = $pageIndex; } // Construct all the LI tags here for($index = 0, $count = sizeof($pageArray); $index < $count; $index++) { if ( $index == $default ) { print '<li class="active">' . $pageArray[$index] . '</li>'; } else { print '<li>' . $pageArray[$index] . '</li>'; } } // Print the closing UL print '</ul>'; } ?> home.php <?php include_once('commonInclude.php'); // The menu section getLink(0); ?> page1.php <?php include_once('commonInclude.php'); // The menu section getLink(1); ?> And so on.... Does it make sense? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.