Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
113
rated 0 times [  114] [ 1]  / answers: 1 / hits: 15281  / 12 Years ago, wed, july 11, 2012, 12:00:00

I need to hide a div if the url of the page contains a certain word. Thanks to this site I have been able to successfully find if the url contains the word. This code works:



<script type=text/javascript>
if (window.location.href.indexOf(Bar-Ends) != -1) {
alert(your url contains bar ends);
}
</script>


but for some reason it will not work to hide a div, like this:



<script type=text/javascript>
if (window.location.href.indexOf(Bar-Ends) != -1) {
$(#notBarEnds).hide();
}
</script>

<div id=notBarEnds>this is not bar ends</div>


Anyone have any idea what is wrong with this code?
Any help is greatly appreciated
Thanks


More From » jquery

 Answers
3

Notice the reorder:



<div id=notBarEnds>this is not bar ends</div>

<script type=text/javascript>
if (window.location.href.indexOf(Bar-Ends) != -1) {
$(#notBarEnds).hide();
}
</script>


Or



<script type=text/javascript>
$(document).ready(function () {
if (window.location.href.indexOf(Bar-Ends) != -1) {
$(#notBarEnds).hide();
}
}
</script>


Waiting for the entire document to be ready


[#84329] Tuesday, July 10, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jaidyn

Total Points: 633
Total Questions: 102
Total Answers: 100

Location: Trinidad and Tobago
Member since Thu, Dec 1, 2022
2 Years ago
;