html - change <a> class place when change page -


how can include class="selected" in different pages?

my code:

                    <li><a href="index.html" class="selected">home</a></li>                                                  <li><a href="register.html">register</a></li>                                                                                            <li><a href="faq.html">faq</a></li> 

so after want go in other pages

                    <li><a href="index.html" >home</a></li>                                                  <li><a  href="register.html" class="selected">register</a></li>                                                                                          <li><a  href="faq.html" >faq</a></li> 

ps: use header.php, manage pages

in pages use:

// include header require_once(site_templates_path . '/partial/_header.inc.php'); 

anyone can tell me how can that?

you can use simple jquery code first don't forget add head tag :

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js" type="text/javascript"></script> 

then can use script :

$(document).ready(function() { var path = window.location.pathname; var page = path.split("/").pop(); //nav nav tag if putting links in nav if not can use selector of class or id $("nav a").each(function(){ var x=$(this).attr("href"); if((x.indexof(page)!=-1)&&(page!="")){ $(this).parent().addclass("selected"); } });  }); 

Comments

Popular posts from this blog

python - Mongodb How to add addtional information when aggregating? -

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

java - Incorrect order of records in M-M relationship in hibernate -