简体   繁体   中英

How to disable cluetip when title is empty?

The cluetip is displaying an empty "div" if title is empty. How to disable the cluetip when title is empty?

jQuery:

$(document).ready(function () {
        $('a.myClass').cluetip({
            splitTitle: '|',
            showTitle: false,                
            width: 400,
            tracking:true
        });
    });

Html:

<a class="myClass" title="" >Sample Text</a>
<a class="myClass" title="Samle Title" >Sample Text2</a>

When title is present the cluetip is displaying correctly. But when title is empty the cluetip should not be displayed(currently displaying an empty div). How to do it?

Simply bind to anchors which have a title (or a non-empty one):

   // with title attribute present
   $('a[title].myClass').cluetip({
        splitTitle: '|',
        showTitle: false,                
        width: 400,
        tracking:true
    });

   // with an non-empty title
   $('a[title!=""].myClass').cluetip({
        splitTitle: '|',
        showTitle: false,                
        width: 400,
        tracking:true
    });

Filter out the anchors with no title or empty title using the filter function

$('a.myClass').filter(function() {
    return this.title !== '';
})​.cluetip({
    splitTitle: '|',
    showTitle: false,                
    width: 400,
    tracking:true
});

http://jsfiddle.net/a9ECE/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM