Reputation: 35194
var currentClassName = $(this).parent('td').next('td').find('input:text').attr('class');
if (currentClassName == undefined) {
currentClassName = $(this).parent('td').find('input:text').attr('class');
}
This works, but i suppose it can be written in one row? Im not really satisfied with this solution. Thanks
Upvotes: 0
Views: 1688
Reputation: 2987
Actually, I think you should be able to check the existence of a class using the attribute jQuery selector:
if ($(this).parent('td').next('td').find('input:text[class]').length != 0) {
// do something
}
Upvotes: 0
Reputation: 9027
var currentClassName = $(this).parent('td').next('td').find('input:text').attr('class');
currentClassName = (currentClassName == undefined ? $(this).parent('td').find('input:text').attr('class') : currentClassName);
Upvotes: 0
Reputation: 100175
if ($(#elm).is('.classname')) { //#elm has the class } else { //#elm doesn't have the class }
Upvotes: 1