-3

I have the following code in my header -

<script type="text/javascript">
if ($("#comments").hasClass("comments-list")) {
    javascript:document.getElementById('g-aside').style.width='0px';
    javascript:document.getElementById('g-aside').style.marginleft='100%';
    javascript:document.getElementById('g-aside').style.visibility='hidden';
    javascript:document.getElementById('g-main').style.width='100%';
}
</script>

It does not work for some reason... The following page is the one i am attempting to adjust.

http://luogocomune.net/LC/index.php/20-varie/4290-benvenuti-sul-nuovo-sito

brigitte18
  • 125
  • 1
  • 13
  • 3
    Why are you writing `javascript:` before every statement? Also the `margin-left` property is accessible via `.style.marginLeft`, not `.style.marginleft`. – Sebastian Simon Nov 29 '15 at 10:51
  • 1
    The console says “`$` isn’t defined”, which means that you didn’t include jQuery before the script where you use it. Also, if this code is in your ``, then you need to [load the DOM first or move the script to the bottom](http://stackoverflow.com/a/8716680/4642212). – Sebastian Simon Nov 29 '15 at 10:55
  • You might want to read [How do I ask a good question](http://stackoverflow.com/help/how-to-ask), which enhances the probability for getting a useful answer _drastically_. You might find [ESR](https://en.m.wikipedia.org/wiki/Eric_S._Raymond)'s excellent essay [How To Ask Questions The Smart Way](http://catb.org/~esr/faqs/smart-questions.html) helpful. Add a [minimal, complete and verifiable example](http://www.stackoverflow.com/help/mcve). – Markus W Mahlberg Nov 29 '15 at 11:48

1 Answers1

2

First of all, include the jQuery library before this script block of yours.

Then, change your script block to:

    <script type="text/javascript">

    $(document).ready(function(){
      if ($("#comments").hasClass("comments-list")) {
        $('#g-aside').css('width','0px')
          .css('margin-left','100%')
          .css('visibility','hidden');
        $('#g-main').css('width','100%');
      }
    });

    </script>

Readup: http://api.jquery.com/css/

Rahul Desai
  • 13,802
  • 14
  • 75
  • 128
  • @brigitte18 No problem. Please make sure that you understand my answer. Feel free to ask me if you have any doubts/questions. – Rahul Desai Nov 29 '15 at 11:10