Need a little help. Correct style and functionality

in Script development
Subscribe to Need a little help. Correct style and functionality 3 posts, 2 voices

Bruno Tyndall User

I am just getting started and have trouble understanding why my little test script doesn't work. I have pasted the script (below).

1) none of the variations that I have tried work on the "lnk.addEventListener" line work.
2) I'd really like to make that call the function test() which is also included in the code below.

Thanks for your help,
B. Tyndall

// ==UserScript==
// @name test
// @description test
// @include http://*
// @copyright Bruno Tyndall
// ==/UserScript==

var test = function() {
alert("Hello World");
var main = function() {
var b = document.getElementsByTagName('body')[0];
var d = document.createElement('div'); = 'absolute'; = 1000; = '5px'; = '80px';
var lnk = document.createElement('a');
var tn = document.createTextNode('Hello World');
lnk.addEventListener('onclick', function(e) { alert('hello'); }, false);



Itamar Amith Scriptwright

Try replacing 'onclick' with 'click'. You can call test() from within the anonymous function.

Bruno Tyndall User

Thanks. That did the trick.