MyBB Community Forums

Full Version: jQuery Help
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
So I've been trying to get this to work for a bit, and can't seem to. Without using the icon variable (Declaring the class directly) it works fine, but I want it to still work fine if the user changes the icon without them having to edit JS. Any ideas why this isn't working?

$('.forum-descrip').hide();
$('.thead').hover(function(){
    var icon = $('.forum-descrip').find('i').attr('class');
    if ($(this).find('span').html() !== "<i class='"+icon+"'></i> ") {
        $(this).find('span').fadeIn();
    } 
}, function(){
    $(this).find('span').fadeOut();
});

Also adding alert(icon); in there shows that it's definitely finding the right class. However hovering a forum still shows the pin icon, even if there isn't any text set.

Edit: :headdesk: nvm got it working with this code:

$('.forum-descrip').hide();
$('.thead').hover(function(){
    var description = $(this).find('span');
    var icon = $('.forum-descrip').find('i').attr('class');
    if (description.html() !== "<i class=\""+icon+"\"></i> ") {
        description.fadeIn();
    } 
}, function(){
    $(this).find('span').fadeOut();
});

(Was using ' instead of " in the if statement)