Skip to content Skip to sidebar Skip to footer

$(location).attr('href'); Not Working

I do not know why but I have problems with this code. The banner is displayed on every page although it has specified the attribute $(location).attr('href') you can help me?:

Solution 1:

Don't you mean just location.href?

This is assuming you are talking about window.location and not something else.

Returns a Location object, which contains information about the URL of the document and provides methods for changing that URL. You can also assign to this property to load another URL.

Location is not an element in the dom thus jQuery can not select it.

So your code would be like so:

var currentUrl = window.location.href;

Solution 2:

location is not a DOM Element, it is a Location object. You are trying to create a jQuery object from it, but it does not make sense.

Use this instead:

var currentUrl = window.location.href;

Solution 3:

Try this

var currentUrl = window.location.href;

Solution 4:

Try using var currentUrl = window.location.href instead. This will return the location of the current page.

Solution 5:

Instead of

$(location).attr('href'); 

use

currentUrl = location;

Post a Comment for "$(location).attr('href'); Not Working"