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.');
}