[Greasemonkey] custom element properties

Nikolas Coukouma lists at atrus.org
Tue Aug 23 14:18:11 EDT 2005


Timothy Babych wrote:

> Hello everybody.
>
> I used to use custom properties of elements in my scripts.
> With inroduction of GM 0.5 this trick does not work anymore in Deer Park
> while working well in FF 1.0.x

In this case, you can use setAttribute and getAttribute. Here's the
script that works in 0.5:
// ==UserScript==
// @name           TeST
// @include      *
// ==/UserScript==

function hello() {
    window.alert(this.my_param)
}

a = document.createElement('a')
linktxt = document.createTextNode('A node')
a.appendChild(linktxt)
// use setAttribute
a.setAttribute("my_param", 111);

document.body.appendChild(a)
a.addEventListener('click', hello, false)

// use getAttribute
window.alert(a.getAttribute("my_param"));


More information about the Greasemonkey mailing list