I currently have this bit of jQuery I am using to append a URL with some location information.
jQuery('a').attr('href', function() {
return this.href + "&location=/123/abc";
});
My issue is most links have a ? in which makes for the use of the above & ok. There are a select few that dont. I am looking to check the url to see if there is a ?. If there is I want to use "&location=/123/abc", if there is no ? I will need to use "?location=/123/abc"
I am not the best with if/else statements. Any help would be appreciated.
if (thereIsA?InTheUrl) {
return this.href + "&location=/123/abc";
} else {
return this.href + "?location=/123/abc";
}
Something like that, just not sure oh to write it.