
Gabriel F. answered 10/31/19
Tutor
5.0
(85)
Full stack Javascript Engineer
Hi there. In the case of Facebook they simply display "(notifications.length) Facebook" or "Facebook". That could be achieved by doing something like this:
$.ajax({
type: 'GET',
url: '<data-api-endpoint>',
dataType: 'json',
success: function(data){
var updatedTitle = data.notifications.length
? `(${data.notifications.length}) Facebook`
: 'Facebook';
$(document).prop('title', updatedTitle);
},
error: function(){
// provide feedback if you want to
}
});
I hope this helps!