Created
June 8, 2018 07:05
-
-
Save jerinisready/e01cb318ef85702854779291a19bfd9c to your computer and use it in GitHub Desktop.
Sometimes we require to reset a canvas when we want to replace the graph with another set of data. that time simply resigning may cause issue, we can reomove and recreate elements for that purpose
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function reset_element(element_id, element_type){ | |
| var child = document.getElementById(div_id); | |
| var parent = child.parentElement; | |
| var new_child = document.createElement(element_type); | |
| parent.removeChild(child); | |
| new_child.setAttribute('id', div_id); | |
| parent.appendChild(new_child); | |
| } | |
| // <span id="my_canvas_id"></span> | |
| // <canvas id="my_span_id"></canvas> | |
| reset_element('my_canvas_id', 'canvas'); | |
| reset_element('my_span_id', 'span'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment