I have the following code, when the user click on toggle to show content, I want to add a hash and id to the url (http://www.somedomain.com/test.html#2111) . When closed I want to remove the #2111.
How do i do that using the toggle?
CSS
.toggle{
display:inline-block;
height:48px;
width:48px;
background:url("http://icons.iconarchive.com/icons/pixelmixer/basic/48/plus-icon.png");
}
.toggle:after{
content:"View All";
display:block;
height:48px;
line-height:48px;
width:288px;
margin-left:48px;
}
.toggle.expanded:after{
content:"Close All";
}
.toggle.expanded {
background:url("http://cdn2.iconfinder.com/data/icons/onebit/PNG/onebit_32.png");
}
JQUERY
$(document).ready(function () {
var $content = $("div.moreinfo").hide();
$(".toggle").on("click", function (e) {
$(this).toggleClass("expanded");
if($(this).hasClass('expanded')) {
$("div.plus").hide().removeClass("closed");
$("div.minus").show().addClass("opened");
} else {
$("div.plus").show().addClass("closed");
$("div.minus").hide().removeClass("opened");
}
$content.slideToggle();
});
});