Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

hadis's avatar
Level 1

clear in todolist

I want to add clear to my to do list but when I click on clear all data in my page clear(refresh page!!)

this is what I did:

function clear(){  
      document.getElementById("todos").id = " "
      tasks = null
}
<li><div class="form-check"><label class="form-check-label"><input class="checkbox" type="checkbox"><p class="todo">'+ item +'</p><i class="input-helper"></i></label><a class="clear" href="" id="clear" onclick="clear()" >clear</a><a class="edit" href="" id="edit" >edit</a></div></li>
0 likes
2 replies
MichalOravec's avatar

@hadis Add return false; to your clear function to prevent the browser from navigating to the link address, in this case href=""

function clear() {
    // your code

    return false;
}
1 like
automica's avatar

@hadis another way to avoid this redirect, is to use a span instead of an anchor tag, and that way you can avoid having the href="" completely.

1 like

Please or to participate in this conversation.