Reputation: 23
How to show this div in the body if the URL contains #people
substring
The URL
www.example.com/user=?232343_ads234324#people
The div
<div id="div1" class="seperate"></div>
Upvotes: 2
Views: 1154
Reputation: 3113
Assuming the element is hidden at the beginning:
if (window.location.hash === "#people") {
$("#div1").show();
}
But if you don't know the state, according to documentation:
$("#div1").toggle(window.location.hash === "#people");
If you want also show and hide this div
with other hashes like #allThePeople
I recommend:
$("#div1").toggle(new RegExp("people", 'i').test(window.location.hash));
// element.visibility (if you can find 'People' in current page URL)
Upvotes: 0
Reputation: 87203
You can use toggle()
, if the URL consists of #people
, #div1
is show, hide otherwise.
$('#div1').toggle(window.location.href.indexOf('#people') > -1);
Upvotes: 1
Reputation: 4736
Try this
var url = document.location.toString();
if (url.match('#people')) {
$('#div1').show();
}
else {
$('#div1').hide();
}
Upvotes: 2
Reputation: 1555
Something like this?
if(window.location.hash != "#people") {
$("#div1").hide();
}
Upvotes: 0