JQuery link error

Joined
Aug 21, 2023
Messages
42
Reaction score
0
Hello. I stuck on a chapter of the book "Learn jQuery 3". The code does well inside dreamweaver but in the browsers(safari, chrome, opera) it does not react at all. When i click on letter A nothig happens. After running the web inspector I got these errors:
Screenshot 1445-02-05 at 09.54.04.png

This is in short the code for it:
<div class="letters"> <div class="letter" id="letter-a"> <h3><a href="entries-a.html">A</a></h3> </div> </div> <div id="dictionary"> </div> ... <script> $(() => { $('#letter-a a') .click((e) => { e.preventDefault() $('#dictionary') .load('a.html'); }); }); </script>
 
Joined
Jul 4, 2023
Messages
609
Reaction score
81
You can't use XMLHttpRequest directly from the browser to local files.
You need use some server application e.g. XAMPP or Alternatives for Hosting Your Website Locally or use some online IDE.

[ on-line ]
HTML:
<html>
    <head>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.0/jquery.min.js"></script>
    </head>
    <body>
        <div class="letters">
            <div class="letter">
                <h3>
                    <a href="#">A</a>
                    <a href="#">B</a>
                    <a href="#">C</a>                   
                </h3>
            </div>
        </div>
        <div id="dictionary"></div>

        <script>
            $(() => {
                $('.letter').click((e) => {
                    e.preventDefault();
                    var letter = e.target.textContent.toLowerCase();
                    $('#dictionary').load(`${letter}.html`);
                });
            });
        </script>
    </body>
</html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,470
Messages
2,571,807
Members
48,797
Latest member
PeterSimpson
Top