I'm learning MooTools and converted some javascript into a MooTools class.
Please note that the number of hyperlinks generated by the server are completely variable. Although the following appears to work fine is there a better way than using 'onclick'?
Yes, inline event handlers are in almost all cases a bad idea.
With MooTools you can use .addEvent.
so you have this html:
<a href="#" id="link">some text</a>
and this JS
$('link').addEvent('click', function(event){
event.preventDefault(); // prevents the default action (which is the
"return false" in your code")
myclass.myfunc(....);
> I'm learning MooTools and converted some javascript into a MooTools class.
> Please note that the number of hyperlinks generated by the server are
> completely variable. Although the following appears to work fine is there
> a better way than using 'onclick'?
Thank you for responding. Your suggestions gave me a good starting point for me to avoid inline event handlers, i.e.: onclick="myclass.myfunc(param1,param2);
On Sunday, November 11, 2012 8:57:28 AM UTC-6, Arian Stolwijk wrote:
> Yes, inline event handlers are in almost all cases a bad idea.
> With MooTools you can use .addEvent.
> so you have this html:
> <a href="#" id="link">some text</a>
> and this JS
> $('link').addEvent('click', function(event){ > event.preventDefault(); // prevents the default action (which is the > "return false" in your code") > myclass.myfunc(....); > });
> On Sun, Nov 11, 2012 at 3:51 PM, Jeff Dunlap <jeff_j...@yahoo.com<javascript:> > > wrote:
>> I'm learning MooTools and converted some javascript into a MooTools >> class.
>> Please note that the number of hyperlinks generated by the server are >> completely variable. Although the following appears to work fine is there >> a better way than using 'onclick'?
· you can chain addEvent right on the result of $$(). $$() returns an
array of Elements, and you can run any Element method, such as
addEvent() on Elements as well, and it will map each item in the array
to the method
· use data-* attributes and you don't need to pollute the href
attribute, which should be useable in scriptless environments or at
the very least give a nice display in the status bar
· simple split() instead of eval -- eval must be destroyed
> · you can chain addEvent right on the result of $$(). $$() returns an > array of Elements, and you can run any Element method, such as > addEvent() on Elements as well, and it will map each item in the array > to the method
> · use data-* attributes and you don't need to pollute the href > attribute, which should be useable in scriptless environments or at > the very least give a nice display in the status bar
> · simple split() instead of eval -- eval must be destroyed
> · you can chain addEvent right on the result of $$(). $$() returns an > array of Elements, and you can run any Element method, such as > addEvent() on Elements as well, and it will map each item in the array > to the method
> · use data-* attributes and you don't need to pollute the href > attribute, which should be useable in scriptless environments or at > the very least give a nice display in the status bar
> · simple split() instead of eval -- eval must be destroyed