We would like to know how to append a Method to DOM Elements.
<!DOCTYPE html>
<html>
<head>
</head><!--from w w w.j av a2 s. c o m-->
<body>
<span id="test">test</span>
<script type='text/javascript'>
var test = document.getElementById('test');
test.foo = function() {
this.style.color = 'red'
}
test.foo()
</script>
</body>
</html>
The code above is rendered as follows: