Community
    • Login

    Javascript not working when launch in chrome

    Scheduled Pinned Locked Moved General Discussion
    cssjavascripthtml
    2 Posts 2 Posters 3.8k Views 1 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Paul JeramP Offline
      Paul Jeram
      last edited by

      Hi Everyone,

      I have been learning web programming for the past year as a hobby and love NP++. However I have some issues with certain Javascript functions working and some that do not.

      I am having real trouble in getting this particular function t run when launched in chrome. From research the coding looks correct but it just won’t work…can someone please give me some advise. I do not know if it a setting or a feature or a plugin that is not set in NP++.

      Any help would be most appreciated…below is the code for the particular that does not work in NP++. I have many other pages to my site with javascript working fine but not this.

      <!DOCTYPE html>
      <html>
      <head>
      <title>Test Page</title>
      <meta name=“viewport” content=“width=device-width, initial-scale=1”>
      <meta charset=“UTF-8”>
      <script src=“https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js”></script>
      <script>
      $(“#carQuestion span”).click(function(){
      $(“#carQuestion span”).removeClass(‘correct’);
      $(this).addClass(‘correct’);
      });
      </script>
      <style>
      .correct { color: red; }
      span:hover { cursor: pointer; }
      </style>
      </head>
      <body>
      <p id=“carQuestion”>What Car is most like me?
      <br><span class=“correct”>Ferrari</span>
      <br><span>Limousine</span>
      <br><span>SUV</span>
      <br><span>Stationwagon</span>
      </p>
      </body>
      </html>

      1 Reply Last reply Reply Quote 0
      • jjstiffJ Offline
        jjstiff
        last edited by

        this is not a notepad++ issue, it is a javascript/jquery question.

        The DOM element refrenced by $("carQuestion span") is not yet defined when the script is run so the click method is not applied to any DOM element.

        You must either wrap your script with $(document).ready(function(){ ... }) or move your script tag to just before </body>

        https://api.jquery.com/ready/

        1 Reply Last reply Reply Quote 0

        Hello! It looks like you're interested in this conversation, but you don't have an account yet.

        Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

        With your input, this post could be even better 💗

        Register Login
        • First post
          Last post
        The Community of users of the Notepad++ text editor.
        Powered by NodeBB | Contributors