0

Using this thread I carried out my header into the individual html file

header.html:

<div class="navbar navbar-default navbar-fixed-top" id="top" role="banner">
  <div class="container">
    <div class="navbar-header">
      <button class="navbar-toggle" type="button" data-toggle="collapse" data-target=".navbar-collapse">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
    </div>
    <div class="navbar-collapse collapse" role="navigation" style="height: auto;">
      <ul class="nav navbar-nav">
        <li><a href="/page1.html">Page1</a></li>
        <li><a href="/page2.html">Page2</a></li>
      </ul>
    </div>
  </div>
</div>

and included it in my index.html.

<script src="https://code.jquery.com/jquery-1.10.2.min.js"></script>
<script> 
$(function(){
  $("#navbar-header").load("header.html"); 
  $("#footer").load("footer.html"); 
});
</script>

and

<div id="navbar-header"></div>

My question is, how to apply 'active' class on selected page (page1 and page2)?

<li class="active"><a href="/page1.html">Equator Server</a></li>
Community
  • 1
  • 1
fen1ksss
  • 1,002
  • 5
  • 19
  • 42

2 Answers2

0

You can call a jQuery Click() event on target element by adding a click event listener on source element (an element which should activate a link on another html).

$('.icon-bar-1').on('click', function(){
  $('.page-1').click(function(){/* code to perform on targetted click listener */});
});
nsthethunderbolt
  • 1,979
  • 1
  • 15
  • 23
  • Andrejs, thank you for your answer could you please make it clear, is it necessary to put a class inside
  • tag?
  • Page1
  • . Or how is that works? – fen1ksss Aug 04 '14 at 13:06