2

Hey guys I'm trying to get the following to work...

  • demo_test.txt to load into the "div1" container
  • only have a href id "test" to trigger it

<!DOCTYPE html>
<html>

<head>
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
  <script>
    $(document).ready(function() {
      $("test").click(function() {
        $("#div1").load("demo_test.txt");
      });
    });
  </script>
</head>

<body>

  <div id="div1">
    <h2>Let jQuery AJAX Change This Text</h2>
  </div>

  <a id="test" href="#">Get External Content</a>

  <br>

  <a id="google" href="http://www.google.com/">Google</a>

</body>

</html>

Currently it doesn't run, but if I remove the Google line, it works. Is there something else I'm missing? Thanks!

2
  • 1
    There's no way that removing the google line could make it run. The problem is clearly due to the missing # in the $("test") selector. Commented Mar 12, 2015 at 3:45
  • 1
    Also, it looks like this is one of your first questions on StackOverflow- so welcome! Unlike on a forum, it's a good idea in the future to stick around on the site for an hour or so after you ask a question - that's when your question will get the most feedback and allow you to further explain your question if it isn't totally clear (in this case you're fine :) ) Commented Mar 12, 2015 at 3:57

1 Answer 1

4

Change your jQuery click handler to this:

$("#test").click(function() {

I've added a # in front of test to properly select your anchor tag.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.