<script src="http://code.jquery.com/jquery-1.7.1.min.js" type="text/javascript"></script>

<script type="text/javascript"> 
$(document).ready(function() {

   $('#navlist li a').click(function(){		
			
	$('#navlist .current').removeClass('current');
	$(this).addClass('current');
        return false;		
   });		
		
});
</script>

<ul id="navlist">
   <li><a href="?p=home"  class="current">Home</a></li>
   <li><a href="?p=product">Our Products</a></li>  
   <li><a href="?p=enquiry">Enquiry</a></li>
   <li><a href="?p=contact">Contact Us</a></li>
   <li><a href="?p=about">About Us</a></li>
</ul>


<div id="content">
  <?php 
	require_once('config.php');
					
	$default = 'home';  
	$page = isset($_GET['p']) ? $_GET['p'] : $default; 
	  if (!file_exists($page.'.php'))    
             { 
	      $page = $default;  
	     } 
	include($page.'.php');
  ?>			
</div>

javascript is used to add and remove class of anchor tag.

Without javascript menu loads pages to content div but when script works it only add and remove class of anchor tag. It stops loading pages to content div.

Recommended Answers

All 3 Replies

Member Avatar for diafol

The links don't fire - you've hijacked them with a return false. Take it off.

BTW - this is a js issue not php.

The links don't fire - you've hijacked them with a return false. Take it off.

BTW - this is a js issue not php.

Thanks.

I removed return false, links are working but now class is not added to new link which is clicked, it is "Home" permanently selected.

can you help me about this,

$('#navlist .current').removeClass('current');
  $(this).addClass('current');

Well, of course. Once you click the link, the page is redirected, and Home is the one selected again. I think you should just use PHP to determine which class to highlight, instead of defaulting to Home.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.