Just clarifying what is happening with the attribute selector.
span[onclick]
selects a span which has an onclick
attribute, regardless of its value.
span[onclick="…"]
selects a span whose onclick
value exactly matches something. That was your error: it didn’t match exactly
span[onclick^="…"]
selects a span whose onclick
value begins with something. That is closer to what you were looking for.
The double quotes around the something aren’t always required, but you do need them if the something contains awkward characters such as slashes. It’s always safe to include them.
Modern CSS also includes $=
which ends with a value, and *=
which contains a value. This is not available in Legacy Browsers (ie IE).
CSS is not sophisticated enough (yet) to include more interesting pattern matches, so although you can look for gotoURL
(span[onclick]^=gotoURL
), there is no way to match gotoURL()
.
Just as a side point, you really shouldn’t be using the onclick
property anyway. It’s only there for people who haven’t heard of unobtrusive JavaScript.