0

hello friends, i so sorry to post this simple question but it is 2 week i'm trying to use jquery on my website but still it is not working,
i have used query in past and it was working pretty fine, and now i'm developing i simple website, i followed a tutorial on internet how to make responsive menu, so it need query i download uncompressed version of jquerry 1.11.1 not working i tried compressed version not working use a cdn <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> still not working i tried 1.9.1 version on CDN still not working what is going wrong with ??
this is the code i use to check if it work

<script>
$('p').css("font-style", "italic");
</script>
3
Contributors
8
Replies
30
Views
2 Years
Discussion Span
Last Post by chrisschristou
0

This depends where you're including it. If in the head section of your page (as noted by Dave):

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
        $(document).ready(function()
        {
            $('p').css("font-style", "italic");    
        });
</script>

You need to use 'ready' as the page won't have loaded by the time attempt the change, so nothing will happen otherwise.
Else, you can place the references just before the </body> tag:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
    $('p').css("font-style", "italic");    
</script>

Here you don't need the ready as the page will have loaded before attempting the change.

0

thanks friends the test worked i wrote the script before </body> and i used

$(document).ready(fucntion)()

now i'm sure that jquery is working i have a script that i linked to my page it is not working i tried two version of code ... i link it in same place before body tag close

$(document).ready(function($){
    $('#header__icon').click(function(e){
        e.preventDefault();
        $('body').toggleClass('with--sidebar');
    });

    $('#site-cache').click(function(e){
        $('body').removeClass('with--sidebar');
    });
})(jQuery);
/* FIRST VERSION */
(function($){
    $('#header__icon').click(function(e){
        e.preventDefault();
        $('body').toggleClass('with--sidebar');
    });

    $('#site-cache').click(function(e){
        $('body').removeClass('with--sidebar');
    });
})(jQuery);
0

Just try it like this:

    <script>
        $(document).ready(function ($)
        {
            $('#header__icon').click(function (e)
            {
                e.preventDefault();
                $('body').toggleClass('with--sidebar');
            });

            $('#site-cache').click(function (e)
            {
                $('body').removeClass('with--sidebar');
            });
        });
    </script>
0

I don't know if I made myself clear. EITHER place it in a 'ready' and place in the head OR leave off the 'ready' and place just before the close body (</body>) tag. You don't need to do both.

0

i dont know what is going on but still it dont work and i got i syntax error on line 8 od dave's code

0

Let me get this straight, you have a syntax error on }); ? You sure about that? Do you have any js before the code shown by DA? Could that be causing the issue?

0

solved the });'s problem still togleclass dont work and remove class dont work can you friends help make this with javascript directy and not with the jquery ??
and i foreget something important should i add somme onClick in this html code to call the script function ??

<a href="#" class="header__icon" id="header__icon"></a>

Edited by chrisschristou

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.