How to bind click event to HTML button node in JavaScript Diagram?
First, create an HTML node with a button. In the JavaScript Diagram, a button for each HTML node must be provided either as a string content or an ng-template to trigger the click event. Below is a code snippet demonstrating how to render the button using an ng-template:
index.html
<script id="nodetemplate" type="text/x-template">
<div style="width:100px;height:100px;background:blue">
<input type="button" id="buttonClick" value="click">
</div>
</script>
index.js
diagram = new ej.diagrams.Diagram({
width: '100%',
height: '645px',
nodes: nodes,
nodeTemplate: '#nodetemplate',
});
To trigger the click event on the button, add the click event inside the button div element. In the below sample, we have bound the click event and changed the shape to basic, and filled the node color.
document.getElementById('buttonClick').onclick = function () {
diagram.nodes[0].shape = { type: 'Basic' };
diagram.nodes[0].style = { fill: 'red' };
diagram.dataBind();
};
Conclusion
I hope you enjoyed learning about how to bind click event to HTML button node in JavaScript Diagram.
You can refer to our JavaScript Diagram feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our JavaScript Diagram example to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!