I'm really confused, other element's onclick is working except this one,
var chatPop = document.createElement('div'),
chatClose = document.createElement('button');
chatPop.classList.add('chat-pop')
chatClose.appendChild(document.createTextNode('X'));
chatClose.onclick = () => $c('chat-pop')[0].remove()
chatHeader.appendChild(chatClose)
chatPop.appendChild(chatHeader)
document.body.appendChild(chatPop)
and the onclick event is not there
There are some issues you need to fix in your script.
chatHeader
variable is undefined
. c
from $c('chat-pop')[0].remove()
and add .
in selector, like this: $('.chat-pop')[0].remove()
.$
function. You also can replace $('.chat-pop')[0].remove()
by document.getElementsByClassName('chat-pop')[0].remove()
.var chatPop = document.createElement('div'),
chatHeader = document.createElement('div'),
chatClose = document.createElement('button');
chatPop.classList.add('chat-pop')
chatClose.appendChild(document.createTextNode('X'));
chatClose.onclick = () => document.getElementsByClassName('chat-pop')[0].remove()
chatHeader.appendChild(chatClose)
chatPop.appendChild(chatHeader)
document.body.appendChild(chatPop)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.