The following code doesn't work. The onClick
events are never fired but I see no errors in browserify or console.
var React = require('react');
var Button = React.createClass({
render: function() {
return (
<div className="Button">
<span className="left" onclick={function() {alert("left")}}>Left</span>
<span className="right" onclick={function() {alert("right")}}>Right</span>
<span className="middle" onclick={function() {alert("middle")}}>Middle</span>
</div>
);
}
});
module.exports=Button;
I use alert just for testing small CSS. Why isn't onclick firing?
You have a typo in your example. Use 'onClick' instead of 'onclick'.
<span className="left" onClick={function() {alert("left")}}>Left</span>
see jsfiddle for a working example - https://jsfiddle.net/Ltdc8qpr/1/
Here with arrow function syntax, triggering the event with onClick handler.
<span className="left" onClick={() => {alert("left")}}>Left</span>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With