Links

Lists

Latest Updates

Ruby On Rails List
Python list
Advanced Java
The JavaScript List
Apache Users
Full Disclosure
Linux Security

Search the archives!


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • From: flavio at economisa.com.br (Flavio Gomes)
  • Subject: [Javascript] item.onclick = "alert('foo');";
  • Date: Mon Nov 7 13:13:33 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@xxxxxxxxxx
> https://lists.LaTech.edu/mailman/listinfo/javascript


-- 
Flavio Gomes
flavio@xxxxxxxxxxxxxxxx