Reputation: 1520
I have this script:
<a href="#extensive" class="forward next-content">Menu item</a>
I can not edit the html. Only the js. This is my js:
// Click
$('.next-content').click(function() {
var url = $(this).attr('href');
console.log(url);
});
When i click on the a button. I get the variable. The href in the variable. The variable is #extensive. But, how can i remove the # from the variable?
Thanks for help
Upvotes: 0
Views: 77
Reputation: 9324
I'm unsure really. This may help. I would have said replace would have been your best option:
url.replace('#', '');
Upvotes: 0
Reputation: 344
You can google it easily...
var url = $(this).attr('href').substr(1);
Upvotes: 0
Reputation: 5462
Can't you just do
// Click
$('.next-content').click(function() {
var url = $(this).attr('href');
url=url.replace("#","");
console.log(url);
});
Upvotes: 0
Reputation: 6126
You can replace the '#' character
url.replace('#','')
or substring
url.substring(1)
Upvotes: 1