I’m looking for a bit of code (jquery if possible) that will remove any file extensions from links. For example
directory/page.html to directory/page
directory2/page2.cfm to directory2/page2
Is this possible?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
jQuery can only select the elements for you, but not process the strings. Simple string manipulation will do it:
lastIndexOfis only supported in IE9 though, so maybe you have to use a regular expression:Update: Regarding your comment, that’s even simpler, just use
You could also restrict the set of links, by only selecting those that actually end with
.cfm: