Prevent Default Event Actions Using MooTools 1.2
Many sweet JavaScript events are trigger by clicking on a link or a submit button. What if you don't want the browser to follow the link? What if you don't want the form to be submitted traditionally? MooTools allows you to prevent the default actions of most elements by using the preventDefault() method.
The Sample XHTML
<p><a href="http://scriptandstyle.com" class="prevent">ScriptAndStyle.com</a></p>
<p><input type="checkbox" class="prevent" /></p>
<p><input type="submit" class="prevent" value="Submit Form" /></p>
The action of any element with the prevent class will be nullified upon click.
The MooTools 1.2 Code
window.addEvent('domready', function() {
$each($$('.prevent'),function(el) {
el.addEvent('click',function(event) {
event.preventDefault();
});
});
});
You can also prevent the browser from allowing image dragging! I did, however, notice that this function did not work correctly on a radio input.
How is it possible that JavaScript-based animation has secretly always been as fast — or faster — than CSS transitions? And, how is it possible that Adobe and Google consistently release media-rich mobile sites that rival the performance of native apps?
This article serves as a point-by-point...
One event that's always been lacking within the document is a signal for when the user is looking at a given tab, or another tab. When does the user switch off our site to look at something else? When do they come back?
A while back David Walsh published a list of
7 MooTools Plugins You Should Use on Every Website
which included 'AutoGrow' a text area expander plugin. 'AutoGrow' is very similar in results to the class I wrote for Education.com, Flext. I decided to release this...
My journey into Dojo JavaScript has been exciting and I'm continuing to learn more as I port MooTools scripts to Dojo. My latest experiment is porting a simple new scroller from MooTools to Dojo. The code is very similar!
The HTML
The news items...
You can use the
$lambda
function and a little bit of the Elements-Class magic to make this a one-liner:@thomasd: Sweet tip!
i found that the method that fails the least is: