How to implement button notification number in jQuery mobile?

I am making jquery mobile application. I want to add a notification number to a button defined as follows.

<a id="resource-button" href="#" data-role="button" data-icon="info" data-iconpos="left">Resources</a> 

Basically, I want that if the number is> 0, it should look like this:

enter image description here

And if its = 0, the number icon should not be displayed at all.

How to implement this?

thank

+4
source share
3 answers

http://jsfiddle.net/gwqn2eqa/

// HTML

<ul data-role="listview">
    <li><a href="http://www.shreerangpatwardhan.blogspot.com">Spatial Unlimited</a>
        <div class="ui-li-count">158</div>
    </li>
    <li><a href="http://shreerangpatwardhan.blogspot.in/p/code-samples.html">Google Maps API Examples</a>
        <div class="ui-li-count">0</div>
    </li>
    <li><a href="http://shreerangpatwardhan.blogspot.in/p/jquery-mobile.html">Jquery Mobile Examples</a>
        <div class="ui-li-count">1</div>
    </li>
    <li><a href="http://www.facebook.com/SpatialUnlimited">Facebook likes - Spatial Unlimited</a>
        <div class="ui-li-count">12</div>
    </li>
</ul>

// JS

$(document).ready(function () {
    $.each($('.ui-li-count'), function (i, v) {
        if($(this).html() == 0) {
            $(this).hide();
        }
    });
});

without list:

// HTML

<span class="ui-li-count ui-btn-corner-all countBubl">12</span>

// CSS

.countBubl {float:left;margin-top:-42px;margin-left:35px;background:#ed1d24;color:#fff;padding:2px;}
+1
source

HTML

<div id="icon">
    <div id="not">3</div>
</div>

CSS

#icon
{
    height:100px;
    width:100px;
    background-color:#bbb;
    position:relative;

}
#not
{
    position:absolute;
    top:-10px;
    right:-10px;
    background-color:#f00;
    width:20px;
    height:20px;
    color:#fff;
    border-radius:20px
    -moz-border-radius:20px;
    -webkit-border-radius:20px;
    text-align:center;
    border:2px solid #fff;

}

JQuery

$(document).ready(function(){
   if($("#not").html()=="0") $("#not").hide();  
});

Attached by Fiddle

+2
source

, , , , status true false.

When a user sends a new message, you add it to the database with the false status. this means that the user no longer sees the message.
in your code we add a new attribute for the link <a>asnotification

<a id="resource-button" notification="4" href="#" data-role="button" data-icon="info" data-iconpos="left">Resources</a> 

in this case we have 4 new notifications for the user.

First of all, we need to check if the notification attribute exists or is not equal to 0, then we do the notifi field.

$(document).ready(function() { 

if( $("#resource-button").hasAttr("notification")) { 
    var num = $("#resource-button").val("notification") ; 
    if (num > 0) { 
        $("#number").css("display", "block") ; 
        $("#number").text(num); 
    }
}
});

CSS for #number:

    #number { 
height: 18px;
width: 18px;
background: url("../images/notification-bg-clear.png") no-repeat scroll center center #F56C7E;
position: absolute;
right: 5px;
top: -10px;
color: #FFF;
text-shadow: 1px 1px 0px rgba(0, 0, 0, 0.2);
text-align: center;
font-size: 9px;
line-height: 18px;
box-shadow: 0px 0px 0px 1px rgba(0, 0, 0, 0.17) inset, 0px 1px 1px rgba(0, 0, 0, 0.2);
border-radius: 9px;
font-weight: bold;
cursor: pointer;
}
0
source

All Articles