>_How to override javascript native method?

Posted 11 years ago  17851 reads  

Yes this is possible. You can override the JavaScript method without destroying the original one.

<script>
if(document.createElement) {
	var superCreateElement = document.createElement;
	document.createElement = function(evt) {
		//console.log("Before calling superCreateElement");
		var ele = superCreateElement.apply(this, arguments);
		//console.log("After calling superCreateElement");
		return ele;
	}
}
var div = document.createElement("div");
div.innerHTML = "Test";
document.body.appendChild(div);
</script>

Powered by HashtagCms.org