How to append to an anchor's href attribute with JavaScript but not affect query string? -
i have links (they in array, not a elements)...
http://example.comhttp://example.com?bob=truehttp://example.com?sandy=true&bob=false
i want append after .com before start of query string.
example
http://example.com/search/resultshttp://example.com/search/results?bob=truehttp://example.com/search/results?sandy=true&bob=false
what best way?
update
i answered own question, if solution can improved (or can see problem it) please post own answer.
i came this...
var append = '/search/results'; anchor.href = anchor.href.replace(/(\?|$)/, append + '$1'); i thought omit parenthesis , reference $0, didn't work me :(
Comments
Post a Comment