I have some simple Javascript (and Jquery) that runs when an <a>
element is clicked
$("a[href^='#']").click(function(e)
{
e.preventDefault();
var element = $($(this).attr("href"));
var position;
// If the href refers to #test
if(element == $("#test"))
{
position = element.offset() + element.height();
console.log("Successful");
}
else
{
position = element.offset().top;
}
}
The if
comparison never seems to work even when the value of element
is equal to $("#test")
in the console and, therefore, it always jumps to the else condition.
It may be worth mentioning that when using breakpoints, both values (element
and $("#test")
) are equal to the following
w.fn.init [section#test.main.special]
What is the reason my comparison is not working?