I am new to JavaScript and using an external file to populate my navigation bar. I would like my navigation tabs to change size/position using my "onTab" class when clicked, and stay that way as long as that navigation tab is supporting the active page. How would the JavaScript go?
I have tried several different onClick and add/remove functions to get this to happen, but apparently I don't know the proper JavaScript series and terms needed for this particular action, yet.
<div id="page-navigator" class="nav-tabs">
<ul class="tabs">
<li class="grow-xs onTab"><a href="" class="tab">Tab A</a></li>
<li class="grow-xs" ><a href="" class="tab">Tab B</a></li>
<li class="grow-xs" ><a href="" class="tab">Tab C</a></li>
<li class="grow-xs" ><a href="" class="tab">Tab D</a></li>
<li class="grow-xs" ><a href="" class="tab">Tab E</a></li>
<li class="grow-xs" ><a href="" class="tab">Tab F</a></li>
</ul>
</div>
EDIT: I know this raw attempt is hilariously wrong, but I "think" I am looking for something like this:
- identify current page url.
- get.elementByClassName "tag"
- look for class "tag" href that is same as URL
- if - class tag is same as page url, add onTab class
$(document).ready(function ($) {
function getURL() {
window.location.href("url")
});
var y = document.getElementsByClassName("tag");
if (x.a[href="window.location.href"]); === y {
toolbar.classList.add('onTab')
}
});