Reputation: 5096
I have the following jQuery:
$('.aboutUs a').live('click', function(e){
e.preventDefault();
var clickedElement = $(this).attr('href');
});
If I console.log the result I will get page.html. What I would like to is remove the .html but not sure how. Can anyone help? Many thanks.
Upvotes: 2
Views: 924
Reputation: 37009
You can use a regex to remove the .html
from the end of the string, eg.
"page.html".replace(/.html$/,'')
Upvotes: 3
Reputation: 166021
You could just replace
the .html
with nothing:
var clickedElement = $(this).attr("href").replace(".html", "");
Note that if your string could potentially contain other instances of ".html" then the regex answer is better, because in that case, this will remove the first occurence rather than the last. But if that's not the case (and it sounds quite unlikely) then this should work fine.
Upvotes: 6