<div id="demo">
<div id="container">
<p>Click for Hello World test.</p>
</div>
<p><a href="http://yuilibrary.com" id="firstA">The YUI Library. (Link navigates away from page.)</a></p>
<a href="http://yuilibrary.com" id="secondA">The YUI Library. (Link's default behavior is suppressed.)</a>
<div class="message">
When you clicked on the second link, *preventDefault* was called, so it did not navigate away from the page.
</div>
</div>
YUI().use('node', function (Y) {
// A function that gives hello world feedback:
var helloWorld = function(e) {
e.target.setHTML("<p>Hello World!</p>");
Y.one('#container').addClass('hello');
}
// subscribe the helloWorld function as an event handler for the click
// event on the container div:
var node = Y.one("#container");
node.on("click", helloWorld);
// A function that displays a message and prevents the default behavior of
// the event for which it is a handler:
var interceptLink = function(e) {
e.preventDefault();
Y.one('.message').setStyle('visibility', 'visible');
}
// subscribe our interceptLink function as a click handler for the second
// anchor element:
Y.one('#secondA').on("click", interceptLink);
});
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.