Skip to content Skip to sidebar Skip to footer

How To Make Li Active When The Code Of The List Is Reusable In Other File

I am having a list which is reused in other webpage so i included it in one file and require the same in other webpage where required I want to make them active for example if MY R

Solution 1:

If you want the active to stay, you COULD use sessionStorage, but why not just ajax the page

https://plungjan.name/SO/ajaxnav/index.html

$(document).ready(function() {
  $("#nav a").on("click", function(e) {
    e.preventDefault();
    // remove classes from all
    $("#nav li").removeClass("active");
    // add class to the one we clicked
    $(this).closest("li").addClass("active");
    $("#content").load(this.href);
  }).eq(0).click();
});
.active {
  background-color: yellow;
}
<scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script><ulid="nav"><liclass="active"><ahref="dashboard.php"><iclass="ti-dashboard"></i>Dashboard</a></li><li><ahref="resume.php"><iclass="ti-wallet"></i>My Resume</a></li><li><ahref="employer-list.php"><iclass="ti-wallet"></i>Browse Jobs</a></li><li><ahref="assess.php?q=1"><iclass="ti-wallet"></i>Assessment</a></li><li><ahref="jobs.php"><iclass="ti-hand-point-right"></i>Applied Jobs</a></li></ul><divid="content"></div>

Post a Comment for "How To Make Li Active When The Code Of The List Is Reusable In Other File"