Reputation: 343
On page load, I'm trying to add the text (capitalized) of the last part of the url to a li
and its attribute data-filter
(with a dot behind).
For example, if the page has this url:
www.myexample.com/#commisions
the li
would look like this:
<ul>
<li><a data-filter=".commisions" href="#">Commisions</li>
</ul>
I have tried with this method but it doesn't remove the #
from the text:
var url = document.URL
var cuturl = url.substr(url.lastIndexOf('/') + 1);
$( ".navbar-brand" ).html( cuturl );
Any idea how can achieve it?
Upvotes: 1
Views: 59
Reputation: 556
Try this
var url = document.URL;
var cuturl = url.split("#")[1];
$("li a").html(cuturl);
$("li a").attr('data-filter','.'+cuturl);
Upvotes: 2
Reputation: 68413
Simply replace "\"
with "#"
var cuturl = url.substring(url.lastIndexOf('#') + 1);
or
var cuturl = url.split("#")[1];
Upvotes: 1