>_How to override javascript native method?

Posted 12 years ago  17987 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