Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide div based on url

Sorry if this is another repost. I have been attempting to find a solution but nothing works that I have tried. I am using a blog which I have full html control over. I can usually find my way around basic html but when it comes to Java or CSS I am a complete newb. Sorry, I know absolutely nothing.

Now that that is out of the way. I have two sidebar div's that I am trying to hide on one specific url to utilize more space for a content iframe. This is one of the coded I have tried to use which doesn't seem to work or I am missing something.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script language="text/javascript"
<?php
&#36;(function(){
      if (window.location.search === "mywebsite/Videos.html") {
            &#36;('#navleft').hide();
      } else {
            &#36;('#navleft').show();
      }
 });
?>
</script>

Please remember I do not know anything when it comes to php or java. I want to do this for both #navright and #navleft. Also this is in the CSS section. Thanks for any help!!

#navright{ width: 200px; }
#navleft{ width: 200px; }
#content{ margin:0px; }
like image 696
Ghetto Styles Avatar asked May 28 '26 20:05

Ghetto Styles


1 Answers

It looks like you are using jQuery, you need to include the jQuery javascript file for the browser to understand the syntax.

http://docs.jquery.com/Downloading_jQuery

Also, remove the <?php and ?> tags and change &#36; to $:

And if you are trying to get the current URL, window.location.search should be changed to window.location.pathname

https://developer.mozilla.org/en/DOM/window.location

<script language="text/javascript">
$(function(){
      if (window.location.pathname == "mywebsite/Videos.html") {
            $('#navleft').hide();
      } else {
            $('#navleft').show();
      }
 });
</script>
like image 89
Curtis Avatar answered May 31 '26 11:05

Curtis