I do some jquery-toggle-action to an element and want to append a static id to the URL while it. So this is what I am doing:
$("#trigger").click(function () {
$("#target").css({display: 'inline-block', transition: '0.5s'});
var hash = $(this).attr("href","#added-to-the-uri");
location.hash = hash;
});
But it doesn't generate: xyz.html#added-to-the-uri but this one xyz.html#[object Object]
What do I need to edit for this? Thanks!
In this line:
var hash = $(this).attr("href","#added-to-the-uri");
You are not setting the #added-to-the-uri
to hash
variable. You are setting the value of $(this)
. The attr function returns the $(this) object.
You should add the anchor like this:
$("#trigger").click(function () {
$("#target").css({display: 'inline-block', transition: '0.5s'});
location.hash = 'added-to-the-uri';
});
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments