jQuery doesn't load in my html file, or it doesn't work


panda

I've been creating a kind of simple personal web page and I start with a page that displays a 3x3 image collage in a div where I want the collage to animate and expand its width so I can add a click image , a description of each image on the right.

Anyway, I've written a script for this and I think it should work fine. However, when I load the page in the browser and click the image, the div doesn't expand.

Maybe the problem is that I'm just not linking the script file or the jQuery library properly? Anyway, this is HTML and jQuery code, so can someone tell me what I'm doing wrong?

HTML:

<!doctype html>
<html>
<head>
    <title>Music</title>
    <link href="style.css" rel="stylesheet" type="text/css">
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
    <script src="script.js"></script>
</head>

<body>
    <div class="panel">
        <div class="mosaic">
            <a href="#"><img class="item" src="images/music/thumbs/wsws.jpg"></a>
            <img class="item" src="images/music/thumbs/kida.jpg">
            <img class="item" src="images/music/thumbs/spirit.jpg">
            <img class="item" src="images/music/thumbs/texas.jpg">
            <img class="item" src="images/music/thumbs/floating.jpg">
            <img class="item" src="images/music/thumbs/ashes.jpg">
            <img class="item" src="images/music/thumbs/dataplex.jpg">
            <img class="item" src="images/music/thumbs/twinfantasy.jpg">
            <img class="item" src="images/music/thumbs/usa.png">
        </div>
    </div>
</body>

jQuery(script.js):

var main = function(){
    $(".item").click(function(){
        $(".panel").animate({
            width:"900px";
        },600);
    });
};

$(document).ready(main);
j08691

When you run a jQuery script locally and refer to a CDN (eg Google), you need to change the URL to include the protocol. So change:

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

arrive:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>

Otherwise, the browser will try to load the file from the local filesystem, usually using the file protocolfile://

Related


jQuery doesn't load in my html file, or it doesn't work

panda I've been creating a simple personal web page and starting with a page that displays a 3x3 image collage in a div where I want the collage to animate and expand its width so I can add a click image , a description of each image on the right. Anyway, I've

JQuery function call to load HTML file doesn't work

echao I'm trying to load an html file using the jQuery .load function ( https://api.jquery.com/load/ ) . I created this function in script.js: function loadPost(file) { console.log(file); $("#content").load(file); }; This index.htmllooks like: <html>

My load() function in jQuery doesn't work

Armin Efthari I am trying to load an external HTML file into a div. I try to use function load()in jQuery but it doesn't work. Here is my code: <!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></

jQuery doesn't work with my HTML

vpaladino778 I'm not quite sure why it doesn't work. I got jQuery from Google server but it doesn't recognize my fadeOut. this is my html file <!DOCTYPE html> <html> <title>Prepare your Jimmies</title> <link href='http://fonts.googleapis.com/css?family=Droid+S

jQuery doesn't work with my HTML

vpaladino778 I'm not quite sure why it doesn't work. I got jQuery from Google server but it doesn't recognize my fadeOut. this is my html file <!DOCTYPE html> <html> <title>Prepare your Jimmies</title> <link href='http://fonts.googleapis.com/css?family=Droid+S

jQuery doesn't work with my HTML

vpaladino778 I'm not quite sure why it doesn't work. I got jQuery from Google server but it doesn't recognize my fadeOut. this is my html file <!DOCTYPE html> <html> <title>Prepare your Jimmies</title> <link href='http://fonts.googleapis.com/css?family=Droid+S

jQuery doesn't work with my HTML

vpaladino778 I'm not quite sure why it doesn't work. I got jQuery from Google server but it doesn't recognize my fadeOut. this is my html file <!DOCTYPE html> <html> <title>Prepare your Jimmies</title> <link href='http://fonts.googleapis.com/css?family=Droid+S

jQuery doesn't work in my HTML

username I'm trying to create a simple login page right now, but will need a lot later jQuery, so please suggest a solution. $('.message a').click(function(){ $('form').animate({height: "toggle", opacity: "toggle"}, "slow"); }); @import url(https://fonts.go

javascript/jquery doesn't work on my html

monomer im not sure how but when i run it with chrome and firefox..im the javascript is not working. help me if you can.. when i add this <!doctype html>to my code, the navigation and title also disappear. Here is my HTML <html> <head> <title>final pro

jQuery doesn't work in my HTML

username I'm trying to create a simple login page right now, but will need a lot later jQuery, so please suggest a solution. $('.message a').click(function(){ $('form').animate({height: "toggle", opacity: "toggle"}, "slow"); }); @import url(https://fonts.go

javascript/jquery doesn't work on my html

monomer im not sure how but when i run it with chrome and firefox..im the javascript is not working. help me if you can.. when i add this <!doctype html>to my code, the navigation and title also disappear. Here is my HTML <html> <head> <title>final pro

jQuery doesn't work in HTML file

Bock Bock I've tried multiple ways of importing jQuery, but nothing works. When I run it, everything in the body shows up, but the jQuery function doesn't work. Here is my current code: <!DOCTYPE html> <html> <head> <script type='text/javascript' src="https:/

jQuery doesn't work in HTML file

Bock Bock I've tried multiple ways of importing jQuery, but nothing works. When I run it, everything in the body shows up, but the jQuery function doesn't work. Here is my current code: <!DOCTYPE html> <html> <head> <script type='text/javascript' src="https:/

jQuery doesn't work in HTML file

Bock Bock I've tried multiple ways of importing jQuery, but nothing works. When I run it, everything in the body shows up, but the jQuery function doesn't work. Here is my current code: <!DOCTYPE html> <html> <head> <script type='text/javascript' src="https:/

jQuery .load() doesn't work

cheers I want to load the content of a webpage in a div. Here is my code: <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> When this item is clicked, the web page should be loaded into the content

jQuery .load() doesn't work

cheers I want to load the content of a webpage in a div. Here is my code: <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> When this item is clicked, the web page should be loaded into the content

jQuery doesn't work in HTML

paul0080 I have a form using jquery Datepicker and jquery validation plugin, but it doesn't work. Datepicker cannot be displayed and jquery validation plugin is not validating. HTML <div class="well"> <form class="form-horizontal" method="post" action="#">

jQuery doesn't work in HTML

paul0080 I have a form using jquery Datepicker and jquery validation plugin, but it doesn't work. Datepicker cannot be displayed and jquery validation plugin is not validating. HTML <div class="well"> <form class="form-horizontal" method="post" action="#">

HTML file doesn't work

Sibam I have two versions of the same code. When I add it to the code snippet on this page it works fine. However, for some reason I can't get it to work on my computer. Check out my Dropbox version for some ideas. In both cases I am using the same encoding. I

HTML file doesn't work

Sibam I have two versions of the same code. When I add it to the code snippet on this page it works fine. However, for some reason I can't get it to work on my computer. Check out my Dropbox version for some ideas. In both cases I am using the same encoding. I

External JS file doesn't work in my HTML file

Albert Chantel New to JS, working on D3 visualization, when I serve a html file containing a JS script: <script src="visualization.js" type="text/javascript"></script> I end up with this error message: Failed to load resource: The server responded with a stat

jQuery doesn't work in html file but works in .js file

Siko When I have the test.js file and import the script with: <script defer="defer" src="/js/test.js"></script> Everything works fine...but if I change the above line in the html to: <script defer="defer"> $(document).ready(function () { $(".overv

jquery.shuffleLetters.js file doesn't work in html file

SOR H Below is the html code I used to make jquery work. I want the phrases on the page to be randomly mixed in and then placed as the desired word. For example, the word "DETERMINED" appears as a scramble of actively moving letters, then stops as DETERMINED.