<h1>The Header</h1>
<div id="thediv" >
<form>
<label for="first">First Name:</label>
<input type="text" maxlength="50" size="20" id="first" name="first_name"><br>
<label for="last">Family or Last Name:</label>
<input type="text" maxlength="50" size="20" id="last" name="last_name"><br>
<input type="submit" id="submit" value="Submit">
</form>
</div>
<p>Note that this does not re-bind the event in thediv's onclick attribute, becuase that is not accessed or removed by unbind(). </p>
CSS
div#thediv
{ border: solid red 1px;
width: 50%;
margin: 1em;
}
p
{ font-size: small;
margin-top: 50px;
}
JavaScript
$(document).ready(function(){
var theDiv = $("#thediv");
theDiv.click(function(){
$(this).css("border-color", "blue");
alert("Click!");
});
theDiv.click(function(){
$(this).css("border-color", "blue");
alert("clack!");
});
var theEvents = theDiv.clone(true).data("events");
// Unbind events from the target div
theDiv.unbind("click");
// Put the saved events back on the target div
for (var e in theEvents){
// must iterate through since it's an array full of event handlers
for ( i=0; i<theEvents[e].length; i++ ){
theDiv.bind(e, theEvents[e][i].handler);
}
}
});
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.
Fiddle Pages
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.
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!
Get Fiddle Pages with PRO
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.