Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why I cant use jQuery functionality

I have jquery-2.1.3.js library in the /opt/lampp/htdocs directory and to test it I included it in a html file

<html>
    <body>
        <p>Some paragraph</p>
        <script src="jquery-2.1.3.js">
            $("p").css("color","orange")
            $("body").css("background","#00ff00")
        </script>
   </body>
</html>

From this I expected to change all text within </p> tags to orange and set the </body> background to green but I all I get is simple output : Some paragraph in default color and default background. Why this dont work?

like image 733
lychee Avatar asked Jan 08 '23 17:01

lychee


1 Answers

script elements can have a src attribute or content, but not both. If they have both, the content is ignored (the content is considered "script documentation," not code).

Use another script block for your jQuery script

<script src="jquery-2.1.3.js">
</script>
<script>
    $("p").css("color","orange")
    $("body").css("background","#00ff00")
</script>
like image 75
Satpal Avatar answered Jan 11 '23 10:01

Satpal