eyeeyeyeyyeey
I solved my issue:
I've tried
boton.onclick = recolecta;
But it didn't work
The right solution is:
boton.addEventListener("click",recolecta, true);
Thank you.
On Mar 14, 8:44 pm, Jose Manuel <[email protected]> wrote:
> Thank your for the documentation about Pitfalls and the code.
>
> I'm ashamed because of my programming style :-/
> But, I get an error in the addEventListener line. What do you think is
> the problem?
> Now my code is (with the funcions in the first post):
>
> fi = document.getElementById('links');
> contenedor = document.createElement('div');
> contenedor.id = 'divnotas';
> fi.appendChild(contenedor);
> contenedor.style.color = "red";
> contenedor.style.background = "#000000";
>
> //Crear botón extractor de información
>
> var boton = document.createElement("input");
> boton.type = "button";
> boton.value = "Recolectar info";
> boton.addEventListener("click", recolecta); // I get an error in this
> line. Why?
> contenedor.appendChild(boton);
>
> On Mar 12, 9:47 pm, cc <[email protected]> wrote:
>
> > Use something like this:
>
> > var boton = document.createElement("input");
> > boton.type = "button";
> > boton.value = "Recolectar info";
> > boton.addEventListener("click", recolecta); /* this is the important line
> > -- and don't use recolecta()! */
> > contenedor.appendChild(boton);
>
> > Also, you don't need to keep using getElementById every time; just keep
> > a reference to the element in |contenedor|, and you should be fine.
> > (For details of why you need to use the addEventListener method, see
> > e.g.http://wiki.greasespot.net/XPCNativeWrapper#Expando_Properties)
>
> > By the way, I assume there's some reason you're not currently re-adding
> > the recolecta button after clearing its parent <div>?
>
> > On 2010-03-12 11:45, Jose Manuel wrote:
>
> > > Hello.
>
> > > I'd like to call a function in the onclick event.
> > > What's the problem???
>
> > > Thanks!!
>
> > > My code is:
>
> > > function borralog(){
> > > document.getElementById('divnotas').innerHTML = "";
> > > }
> > > function loguea(texto){
> > > document.getElementById('divnotas').innerHTML += texto + "<br>";
> > > }
> > > /* I've tried...
> > > window.recolecta = function() { // it didn't
> > > work */
> > > function recolecta(){ // it didn't work too
> > > alert ("hola");
> > > borralog();
> > > loguea ("recolectando informaci�n");
> > > }
>
> > > // crear capa de información
> > > fi = document.getElementById('links');
> > > contenedor = document.createElement('div');
> > > contenedor.id = 'divnotas';
> > > fi.appendChild(contenedor);
> > > document.getElementById('divnotas').style.color = "red";
> > > document.getElementById('divnotas').style.background = "#000000";
>
> > > //Crear bot�n extractor de informaci�n
> > > document.getElementById('divnotas').innerHTML = '<input type=button
> > > value="Recolectar info" onClick = "recolecta();">';
>
> > --
> > cc | pseudonymous |<http://carlclark.mp/>
--
You received this message because you are subscribed to the Google Groups
"greasemonkey-users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/greasemonkey-users?hl=en.