JQuery link error

Joined
Aug 21, 2023
Messages
40
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
436
Reaction score
53
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

Forum statistics

Threads
473,861
Messages
2,569,878
Members
46,087
Latest member
KVTRuth63

Latest Threads

Top