Level 75
@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
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
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>
Please or to participate in this conversation.