0

I've looked this over so many times and I can't figure out why my script is not running AT ALL. Any help would be appreciated...

The script....

</head>

<script type="text/javascript">
    $(document).ready(function() {
        $('li#profiles').addClass('active');
        $('#content').load('profiles');

        $('nav ul li a').click(function() {
            $('.active').removeClass('active');
            $(this).parent().addClass('active');
            var link = $(this).parent().attr('id');
            $('#content').load(link);
            return false;
        }); // end click
    }); // end ready
</script>

<body>

within the body I have this....

<nav>
    <ul>
        <li id="profiles"><a href="profiles">Guest Profiles</a></li>
        <li id="config"><a href="config">Configuration</a></li>
    </ul>
</nav>

I have this style set to see if it is working....

<style>
    .active a {color : rgb(80,180,80);}
</style>

When loading my page, the profiles link is the typical blue. I'm using Chrome DevTools and see no changes in the DOM..... Also, when I click on either link, it follows the link instead of the .click.....

Thank you

-John

6
  • 2
    Did you include the jquery library? Commented Jan 4, 2014 at 3:33
  • When selecting by ID, just using ID is enough, try $('#profiles') instead of $('li#profiles') Commented Jan 4, 2014 at 3:34
  • Joren.... sometimes the obvious answer is the right answer! I guess after weeks of trying to figure out laravel, I forgot the basics of javascript... Thank you. Commented Jan 4, 2014 at 3:35
  • @YuriyGalanter Post that as an answer Commented Jan 4, 2014 at 3:39
  • 1
    <sarcasm> This question has my favorite title </sarcasm> Commented Jan 4, 2014 at 3:41

2 Answers 2

2

You probably just need to include the jQuery library. The code you have works fine. Just add this to your head.

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

This fiddle proves that your code is fine.

Sign up to request clarification or add additional context in comments.

Comments

0

It looks like you just forgot to include your jQuery source.

1 Comment

It looks like same answer is given few minutes ago.

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.