Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9309999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T01:00:37+00:00 2026-06-19T01:00:37+00:00

I have been staring at the problem for hours. I am just starting to

  • 0

I have been staring at the problem for hours. I am just starting to learn Jquery and I have a small project that requires me to use a button to clear the elements of an unordered list.

First, I most track the mouse posistion and mouse-click of the user. Each time they click the button, I build an unordered list and record the x,y posistions. Then, I am supposed to use a button to clear the list. Everything seems to work fine, but the button when clicked, adds to the list instead of clearing it.

Can anyone help me spot the issue?

<!doctype html>
<head>
<title>Click away</title>
<link href="stylesheets/standard.css" rel="stylesheet">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script>
var count = 0;
$("html").click(function(){
count++; 
$("#display").html("The click count is: " + count);
});
$("html").click(function(e) {
var xPos = e.pageX;
var yPos = e.pageY;
$("#list").append("<li>" + xPos + ", " + yPos + "</li>");
});
//This is the section I can't get to work
$("#clear").click(function () {
$("#list").remove();
}); 
</script> 
</head>
<body>
<h1> Click away</h1>
<h2>Start clicking...</h2>  
<h2 id="display"></h2>
<button id="clear">Clear the location list</button> 
<h2>Click locations:</h2>   
<ul id="list"></ul>
</body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-19T01:00:38+00:00Added an answer on June 19, 2026 at 1:00 am

    Use $("#list").empty();

    Using $("#list").children().remove(); will also work but the first one is more efficient.

    I think you should also exclude the clear button from your list and put your code inside .ready() handler so that the code executes after DOM is ready and your elements are loaded:

    $(document).ready(function(e) {
    
        var count = 0;
        $("html").click(function () {
            count++;
            $("#display").html("The click count is: " + count);
        });
        $("html").click(function (e) {
            if (e.target !== document.getElementById('clear')) { //exclude the clear button 
                var xPos = e.pageX;
                var yPos = e.pageY;
                $("#list").append("<li>" + xPos + ", " + yPos + "</li>");
            }
        });
    
        $("#clear").click(function () {
            $("#list").empty(); //empty list
        });
    
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem that I have been trying to figure out for hours
I have been staring at this code for few hours, tried walkthrough,debugging with autos
I have a page that i have been starting to setup here http://www.brandybrowauto.com/NEW.html that
I have been for the past several hours trying to do something that I
I have just been trying to fix a few memory leaks in my project
I have a problem that has been driving me crazy and I'd appreciate any
Ok, I have been staring at this for hours trying to figure out what's
I realize that similar questions have been asked, but have spent hours trying to
OK, so I have been searching for hours about my problem but nothing seems
I have been staring at this code and cannot figure out what is wrong

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.