Hi all,
I'm getting some confusing results in jQuery, with attr('class') and hasClass(). Basically, I am traversing through table rows and figuring out if the next visible table row has a certain class.
$('table#blocks tr.region').each(function () {
var next_row = $(this).nextAll('tr:visible');
console.log('This: ' + $(this).attr('class') + ' Next: ' + next_row.attr('class') + ' Next is a region: ' + next_row.hasClass('region'));
});
When I run this script, the log shows:
This: region region-left Next: region region-right Next is a region: true
This: region region-right Next: region region-content Next is a region: true
This: region region-content Next: draggable even shown_on_home shown_on_infozone Next is a region: true
This: region region-header Next: region-message region-header-message region-empty Next is a region: true
This: region region-footer Next: region-message region-footer-message region-empty Next is a region: true
This: region region--1 Next: undefined Next is a region: false
So the message clearly shows that some rows have the class 'region' and some don't, but they all return true for hasClass()!
Can anyone shed some light on this?
Thanks :)