I've recently gotten my first ID job as a PHP programmer but one of the tasks that bites my is JS/jQuery, I don't know JS/jQuery but now i'm having to use it. I'm taking a course on udemy.com but I'm having issues, sometimes the code executes and sometimes noting happens at all, my browser will have absolutely no response. I've just tried the following code with no response whatsoever from either Brave or Google Chrome. Any ideas what could be going wrong here? Thanks.

 <!DOCTYPE html>

<html>

<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> 
<script>
    $(documenet).ready(function(){
        $('p').click(function(){
            $(this).css('color', 'red');
        });

        $('li').dblclick(function(){
            $(this).css('color', 'red');
        });
    });
</script>
</head>

<body>

    <h1 id="title">title</h1>

    <p class="paragraph">Paragraph text 1</p>
    <p class="paragraph">Paragraph text 2</p>

    <input type="text"></input>

    <ul>
        <li>List element 1</li>
        <li>List element 2</li>
        <li>List element 3</li>
        <li>List element 4</li>
        <li>List element 5</li>
    </ul>

</body>

</html>

Dani AI

Generated

Short answer: the immediate cause was the typo in the ready call (as , and pointed out). For intermittent failures there are a few extra checks and practices that make this more predictable and easier to debug.

  • Check the browser console (F12 → Console) first. Look for ReferenceError or SyntaxError messages and for messages like Uncaught ReferenceError: $ is not defined.
  • Confirm jQuery actually loaded (Network tab) or run typeof jQuery in the console; if it reports anything other than "function" the CDN or loading order is the problem.
  • Ensure your jQuery <script> comes before any inline script that uses $, and avoid async on those script tags unless you know the consequences. A single JS syntax error in an earlier script can stop everything that follows.
  • Try disabling Brave shields/ad‑block extensions or test in a plain Chrome profile / incognito window — privacy/blocking can stop CDN scripts from loading. If blocking is suspected, try a local copy of jQuery or a different CDN as a test.

A small, resilient alternative (pure JS) that avoids relying on jQuery readiness is shown below; it uses DOMContentLoaded and event delegation so dynamically added elements are handled too:

document.addEventListener('DOMContentLoaded', function () {
  document.body.addEventListener('click', function (e) {
    if (e.target.tagName === 'P') e.target.style.color = 'red';
  });
  document.body.addEventListener('dblclick', function (e) {
    if (e.target.tagName === 'LI') e.target.style.color = 'red';
  });
});

If the typo fix from resolves the immediate problem, the checklist above will help prevent similar intermittent behavior in future. — after confirming jQuery loads and there are no console errors, the thread can be considered solved.

Recommended Answers

All 4 Replies

What is this "documenet"?

PS. Hi Lew!

commented: I'm a morron! +6

Hi, document is spelt wrong!

$(document).ready(function(){
commented: I'm a morron! +6

Correct the selector: $(document).ready(function() { ...
You wrote $(documenet)

commented: The obvious got me. +6

Can I mark this question as solved? Or does it still not work?

commented: I'm pretty sure it's solved, looks ok to me +0
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.