Tutorial Clear a File Input
You can just clone it and replace it with itself, with all events still attached.
var input = $("#control");
function something_happens() {
input.replaceWith(input.val('').clone(true));
};
You can just clone it and replace it with itself, with all events still attached.
var input = $("#control");
function something_happens() {
input.replaceWith(input.val('').clone(true));
};
if (typeof jQuery == 'undefined') {
// jQuery IS NOT loaded, do stuff here.
}
$('button').click(function(event, wasTriggered) {
if (wasTriggered) {
alert('triggered in code');
} else {
alert('triggered by mouse');
}
});
$('button').trigger('click', true);
Replace the first selector with the child you are testing and the second selector with the parent you are testing for.
if ( $(".child-element").parents("#main-nav").length == 1 ) {
// YES, the child element is inside the parent
} else {
// NO, it is not inside
}
if ($('#myElement').length > 0) {
// it exists
}
Or to make it a fancy function with a callback:
// Tiny jQuery Plugin
// by Chris Goodchild
$.fn.exists = function(callback) {
var args = [].slice.call(arguments, 1);
if (this.length) {
callback.call(this, args);
}
return this;
};
// Usage
$('div.test').exists(function() {
this.append('<p>I exist!</p>');
});
Say that 10 times fast =).
Find out if a single checkbox is checked or not, returns true or false:
$('#checkBox').attr('checked');
Find all checked checkboxes:
$('input[type=checkbox]:checked');
Do something for each empty element found:
$('*').each(function() {
if ($(this).text() == "") {
//Do Something
}
});
TRUE or FALSE if element is empty:
var emptyTest = $('#myDiv').is(':empty');