'How do i become href out of a link
Following problem: I would like to not have to copy my navigation bar over every site. So I wrote it in an extra Document and included it with php. The site ur on has a special class to show its active now that where I'm stuck at. I tried following statement just to see if my idea works
<script> if(document.getElementById("test").href == window.location.pathname){window.alert("wow");}
Spoiler alert it does not:(
I know that the pathname is the same as href(tried it) but I can't get the href like that. Does anybody know how to do that? Sorry for my English
Thanks a lot for helping
PS: I'm just getting into js I usually work with other languages but wanted to get into website design.
Solution 1:[1]
The problem was simple : document.getElementById("test").href gives out the whole link with www even thoug its not standing in there while window.location.pathname just gives out the path like /index.php. I had to use window.location.href instead.
Thanks for all the answers
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | LordPaulHD |
