Side navigation
Ticket #3827: test-3827.html
File test-3827.html, 1.6 KB (added by dmethvin, January 17, 2009 05:31PM UTC)
event handling with jQuery trigger() and DOM events
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Test</title>
<script type="text/javascript" src="jquery-1.3.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$('#butt1').click(function (e) {
$('#cb1').click();
});
$('#cb1').click(function (e) {
$("#log").append("jQuery: "+this.checked+"<br />")
// e.preventDefault();
// return false;
});
document.getElementById("butt2").onclick = function(e){
e = e || event;
document.getElementById("cb2").click();
};
document.getElementById("cb2").onclick = function(e){
e = e || event;
var tgt = e.target || e.srcElement;
document.getElementById("log").innerHTML += "Native DOM: "+tgt.checked+"<br />";
// if ( e.preventDefault )
// e.preventDefault();
// return false;
};
$('#butt3').click(function (e) {
$('#cb3')[0].click();
});
$('#cb3').click(function (e) {
$("#log").append("jQuery+native: "+this.checked+"<br />")
// e.preventDefault();
// return false;
});
});
</script>
</head>
<body>
jQuery: <button id="butt1">Check the checkbox!</button>
<input type="checkbox" name="cb1" id="cb1" /> <br />
Native DOM: <button id="butt2">Check the checkbox!</button>
<input type="checkbox" name="cb2" id="cb2" /> <br />
jQuery+native: <button id="butt3">Check the checkbox!</button>
<input type="checkbox" name="cb3" id="cb3" /> <br />
<div id="log"></div>
</body>
</html>
Download in other formats:
Original Format
File test-3827.html, 1.6 KB (added by dmethvin, January 17, 2009 05:31PM UTC)
event handling with jQuery trigger() and DOM events
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Test</title>
<script type="text/javascript" src="jquery-1.3.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$('#butt1').click(function (e) {
$('#cb1').click();
});
$('#cb1').click(function (e) {
$("#log").append("jQuery: "+this.checked+"<br />")
// e.preventDefault();
// return false;
});
document.getElementById("butt2").onclick = function(e){
e = e || event;
document.getElementById("cb2").click();
};
document.getElementById("cb2").onclick = function(e){
e = e || event;
var tgt = e.target || e.srcElement;
document.getElementById("log").innerHTML += "Native DOM: "+tgt.checked+"<br />";
// if ( e.preventDefault )
// e.preventDefault();
// return false;
};
$('#butt3').click(function (e) {
$('#cb3')[0].click();
});
$('#cb3').click(function (e) {
$("#log").append("jQuery+native: "+this.checked+"<br />")
// e.preventDefault();
// return false;
});
});
</script>
</head>
<body>
jQuery: <button id="butt1">Check the checkbox!</button>
<input type="checkbox" name="cb1" id="cb1" /> <br />
Native DOM: <button id="butt2">Check the checkbox!</button>
<input type="checkbox" name="cb2" id="cb2" /> <br />
jQuery+native: <button id="butt3">Check the checkbox!</button>
<input type="checkbox" name="cb3" id="cb3" /> <br />
<div id="log"></div>
</body>
</html>