What is onclick in HTML?
The Html <button onclick=” “> is an event attribute, which executes a script when the button is clicked. This attribute is supported by all browsers. It is also used to call a function when the button is clicked.
CSS rules can actually contain JS code (supported by at least some browsers), so from that perspective CSS can be “as bad as” JS. There are two different types of issues with untrusted data: It can contain malicious code to be executed directly (malware)
Is Onclick deprecated?
Solution: The HTML onClick is deprecated, It still continues to work in all major browsers but still its considered as a bad practice. Its good practice to have all the different code family separated.
- if(document. getElementById(‘button’). clicked == true)
- alert(“button was clicked”);