Check If Element Has ID Using jQuery
To check if an element has an ID: if ($(this).is('[id]') { // Has ID console.log('Has ID: ' + $(this).attr('id')); } else { // Has no ID console.log('Has no ID.'); }
To check if an element has an ID: if ($(this).is('[id]') { // Has ID console.log('Has ID: ' + $(this).attr('id')); } else { // Has no ID console.log('Has no ID.'); }
Selector Starts With: $('input[name^=somePrefix]').doSomething(); Selector ENDS with: $('input[name$=someSuffix]').doSomething(); In ASP.Net: This is particularly useful in ASP.Net when you may not want to specify clientidmode static, but still want to use [...]
When a DOM object is added after the DOM has loaded, the usual process of binding an event to a specific jQuery object may not be sufficient. E.g.: Normal binding [...]
$.post('status.ajax.php', {deviceId: id}) .done( function(msg) { ... } ) .fail( function(xhr, textStatus, errorThrown) { alert(xhr.responseText); }); http://stackoverflow.com/a/12116790/4669143
Do something after jQuery resize or scroll is done, or has paused. Instead of firing the event every time the resize/scroll is detected, which is constantly during a resize/scroll operation, [...]
$("input").prop('disabled', true); $("input").prop('disabled', false); This will automatically add/remove the 'disabled' property of the element. Source: http://stackoverflow.com/a/1414366/4669143
if ($(selector).length) { // Exists } Source: http://stackoverflow.com/a/587408