I want to stop the eventListener after the function is done, here is the illustration:
I made an icon and when clicked it gonna show the input form
and then when my cursor clicked
or mouseover
it shows the button
search again below that input, but when I click again and over, the button search keep adding the element buttons on below,
Here is the code :
let FunFun = document.querySelector( "img#pic" ).addEventListener( "click", () => {
let newEl = document.createElement("input");
newEl.id = "inPut"
newEl.type = "text";
newEl.name = "foo";
newEl.value = "";
newEl.placeholder = "type your city";
let oldEl = document.querySelector("#pic")
//parentEL
let parentEl = document.querySelector( ".addCity" )
parentEl.replaceChild( newEl, oldEl )
let btN = document.querySelector( "#inPut" ).addEventListener( "click", () => {
btN = document.createElement( "button" )
btN.class = "btn0"
btN.textContent = "search"
let _input = document.querySelector("#inPut")
_input.after(btN)
// tried wrote code removeEventListener also, but nothing error and cant make the event stop
}) end the btN
// console.log(btN)
// let buttnRm = document.querySelector("#inPut").removeEventListener("click", () => { console.log("test" )});
}) // end the FunFun
My code above was no error on the console, and I tried to put the removeEven listener below the function btN
, it got error, like the code above,
I tried to make code like this on function above :
.addEventListener("click", myFunction, true) // false
.removeEventListener("click", myFunction, true) // false
i switch true and false above, but still nothing
some pics of the buttons showing more and more when I click the input
form element, after my function addeventlistener
working