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>

Try this:

    <script>
        $(document).ready(function()
        {
            $('p').css("font-style", "italic");    
        });
    </script>
Member Avatar for diafol

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.

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);

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>
Member Avatar for diafol

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.

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

Member Avatar for diafol

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?

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>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.