1

I have this script in the head of the html:

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js">
    $(function () {
        $('.nav-toggle').on('click',function(){
            $('.mainnav').toggleClass('open');
        });
    });
</script>

which should fire when:

<header>
    <img class="nav-toggle" src="static/images/menunav.png" style="cursor: pointer;">
</header>

this image is clicked.

and toggle the subclass open in:

<ul class="text mainnav">
        <li>Home</li>
        <li>Projects</li>
        <li>Techniques</li>
        <li>About me</li>
    </ul>

But it wont fire the .open class? What am i doing wrong here (first time jquery user).

CSS:

.nav-toggle {
  float: right;
  margin-right: 70px;
}

    .mainnav{
      position: fixed;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      background: #222;
      text-align: center;
      list-style: none;
      display: inline-block;
      transform: translateX(-100%);
      transition: transform 0.6s ease;
    }

    .mainnav.open {
      transform: translateX(50%);
}
3
  • 3
    Seems to work just fine -> jsfiddle.net/adeneo/syuqmyr1 Commented Oct 16, 2016 at 15:47
  • Yeah, it works. Commented Oct 16, 2016 at 15:48
  • Sounds like you forgot to wait for $(document).ready(). Commented Oct 16, 2016 at 16:04

1 Answer 1

3

I guess the problem is in the html. Try to split

<script src="[JQuery CDN]"></script>
<script>
$(function(){ ... });
</script>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.