Search the archives!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Javascript] item.onclick = "alert('foo');";
- From: rer at datacompusa.com (Roger Roelofs)
- Subject: [Javascript] item.onclick = "alert('foo');";
- Date: Mon Nov 7 08:46:50 2005
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.
- Follow-Ups:
- [Javascript] item.onclick = "alert('foo');";
- From: Flavio Gomes
- [Javascript] item.onclick = "alert('foo');";
- From: Anthony Ettinger
- [Javascript] item.onclick = "alert('foo');";
- From: diego nunes
- [Javascript] item.onclick = "alert('foo');";
- References:
- [Javascript] item.onclick = "alert('foo');";
- From: Anthony Ettinger
- [Javascript] item.onclick = "alert('foo');";
- Prev by Date: [Javascript] item.onclick = "alert('foo');";
- Next by Date: [Javascript] item.onclick = "alert('foo');";
- Previous by thread: [Javascript] item.onclick = "alert('foo');";
- Next by thread: [Javascript] item.onclick = "alert('foo');";
- Index(es):