[Javascript] item.onclick = "alert('foo');";

Flavio Gomes flavio at economisa.com.br
Mon Nov 7 12:18:18 CST 2005


 There's another problem:
  If the element that has the "foo" id is declared below the script 
block and it is an "inline" script it will not find the "foo" object..

Try an "alert(item)" and you'll see what I meant


Roger Roelofs escreveu:

> Anthony,
>
> On Nov 6, 2005, at 6:01 PM, Anthony Ettinger wrote:
>
>> this doesn't seem to work:
>>
>> var item = document.getElementById('foo');
>> item.onclick = "alert('foo');";
>>
>> http://developer.mozilla.org/en/docs/DOM:element.onclick
>
>
> I wouldn't expect it to.  You need to assign a function to onclick 
> rather than some text.
>
> var item = document.getElementById("foo");
> if ( item ) {
>     item.onclick = function() { alert("foo") };
> }
>
> I've never seen it done the way it is in the first example on the page 
> you cite.  I could be wrong, but it looks like a documentation bug to me.
>
> hth
> Roger,
>
> Roger Roelofs
> Know what you value.
>
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript


-- 
Flavio Gomes
flavio at economisa.com.br




More information about the Javascript mailing list