Plenty of answers telling you to use attr instead of val -- the return value is still undefined because you have not split your string sufficiently to have just the query arguments. You end up checking if "p" === "http://example.com/?p".