How can I remove a query string from the url of a link? For example I have
<a href="http://example.com/somepath/anotherpath?title=dog">The Link</a>
How can I remove just the ?title=dog from the url using javascript/jquery?
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.
You can remove the query string from a link by simply changing the
searchproperty of the Location object.Demo: http://jsfiddle.net/uSrmg/1/
Or if you need to target multiple elements:
Demo: http://jsfiddle.net/uSrmg/4/
If you wish to parse an arbitrary URL to remove the query string, you can inverse the trick explained in this post. For example:
This should be quite robust as it uses the Location object to do all the parsing.
Example usage: http://jsfiddle.net/uSrmg/