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.