Jquery is a very popular Javascript Library which is easy to use, saves development cost and time. It reduces the amount of Javascript code on a page with easy to use syntax. Jquery contains library for rich user interface widgets which can be used in web forms.
Example Javascript code to get an element:
var element = document.getElementById("elementId");
Jquery syntax:
var element = $("elementId");
How to check/uncheck all checkbox in a gridview using jquery:
function ToggleSelection(ctrl, chk) {
$('#<%=gvProducts.ClientID %> :checkbox[id$=' + chk + ']').attr('checked', ctrl.checked);
}
Detect/Trigger window.print() event using javascript
function loadPrint() {
window.print();
setTimeout(function () { window.close(); }, 100);
}
otherwise,
(function() {
var beforePrint = function() {
console.log('Before printing.');
};
var afterPrint = function() {
console.log('After printing');
};
if (window.matchMedia) {
var mediaQueryList = window.matchMedia('print');
mediaQueryList.addListener(function(mql) {
if (mql.matches) {
beforePrint();
} else {
afterPrint();
}
});
}
window.onbeforeprint = beforePrint;
window.onafterprint = afterPrint;
}());
Detect/Trigger window.print() event using jquery
<script>
window.onafterprint = function(e){
$(window).on('mousemove', window.onafterprint);
console.log('Print Dialog Closed...');
};
window.print();
setTimeout(function(){
$(window).on('mousemove', window.onafterprint);
}, 1);
</script>
Example Javascript code to get an element:
var element = document.getElementById("elementId");
Jquery syntax:
var element = $("elementId");
How to check/uncheck all checkbox in a gridview using jquery:
function ToggleSelection(ctrl, chk) {
$('#<%=gvProducts.ClientID %> :checkbox[id$=' + chk + ']').attr('checked', ctrl.checked);
}
Detect/Trigger window.print() event using javascript
function loadPrint() {
window.print();
setTimeout(function () { window.close(); }, 100);
}
otherwise,
(function() {
var beforePrint = function() {
console.log('Before printing.');
};
var afterPrint = function() {
console.log('After printing');
};
if (window.matchMedia) {
var mediaQueryList = window.matchMedia('print');
mediaQueryList.addListener(function(mql) {
if (mql.matches) {
beforePrint();
} else {
afterPrint();
}
});
}
window.onbeforeprint = beforePrint;
window.onafterprint = afterPrint;
}());
Detect/Trigger window.print() event using jquery
<script>
window.onafterprint = function(e){
$(window).on('mousemove', window.onafterprint);
console.log('Print Dialog Closed...');
};
window.print();
setTimeout(function(){
$(window).on('mousemove', window.onafterprint);
}, 1);
</script>