Possible Duplicate:
The current element as its Event function param
Would this work
<script type="text/javascript">
var foo = function(param)
{
param.innerHTML = "Not a button";
};
</script>
<button onclick="foo(this)" id="bar">Button</button>
rather than this?
<script type="text/javascript">
var foo = function()
{
document.getElementId("bar").innerHTML = "Not a button";
};
</script>
<button onclick="foo()" id="bar">Button</button>
And would the first method allow me to load the javascript from elsewhere to perform actions on any page element?
The code that you have would work, but is executed from the global context, which means that
thisrefers to the global object.You can also use the non-inline alternative, which attached to and executed from the specific element context which allows you to access the element from
this.