While doing codes something like below:
document.querySelector('input[type=text]').addEventListener('focus', function() {
document.querySelector('#deletebutton').style.display = 'none'
})
input[type=text]:focus+#deletebutton {
display: block;
}
input[type=text]:not(:focus)+#deletebutton {
display: none;
}
<input type='text'>
<button id='deletebutton'>delete</button>
input[type=text]:focus+#deletebutton {
display: block;
}
input[type=text]:not(:focus)+#deletebutton {
display: none;
}
<input type='text'>
<button id='deletebutton'>delete</button>
It seems like JS has more control (higher priority) than CSS does to the HTML button. The input
will follow the rule for JS eventListener
and ignore the CSS pseudo-class
(:focus
).
Does this means CSS has less priority than JS?
Or the css focus
event is a selector, but JS it is an eventListener
where eventListener
is more important?
Or I should put the script in the header before the css stylesheet (now i put it in the body
)
Or all my attempt is wrong?