Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7093457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:26:30+00:00 2026-05-28T08:26:30+00:00

I have a PHP notification system, and the amount of notifications is put into

  • 0

I have a PHP notification system, and the amount of notifications is put into a DIV using jQuery. The only problem is that when there are 0 notifications, the empty DIV still shows up. This is the jQuery I am currently using:

$(document).ready(function() {
    $.get('/codes/php/nf.php', function(a) {
        $('#nfbadge').html(a);
        $('#nfbadge:empty').remove();
    })
});
setInterval(function() {
    $.get('http://localhost/codes/php/nf.php', function(a) {
        $('#nfbadge').html(a);
        $('#nfbadge:empty').remove();
    })
}, 8000);

The only problem is that if at document load there is 0 notifications and a notification is added, the badge will not show up, so basically if the element is removed it won’t come back unless the page is reloaded, but I made the notification system so that the page wouldn’t have to be reloaded. How can I fix this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T08:26:31+00:00Added an answer on May 28, 2026 at 8:26 am

    If you have control over the PHP, you shouldn’t be using jQuery to be removing DIVs, it’s a waste of resources and load time, even if it’s just a few lines of code.

    In your PHP template you should include the #nfbadge div in a conditional statement, something like:

    if($notifications) {
         echo '<div id="nfbadge">';
         //notification stuff
         echo '</div>';
    }
    

    Then with your jQuery code you could do something like the following:

     var $nfbadge = $('#nfbadge');
     if($nfbadge) {$nfbadge.html(a)}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a notification system that works with the following codes jQuery: $(document).ready(function(){$.get('/codes/php/nf.php', function(data)
So I have this notification system that uses jQuery and PHP. The jQuery checks
index.php has this jquery code which loads notifications.inc.php into a div on the page
i have put that url http://pvpcoach.com/notification.php in Instant Payment Notification setting in my profile
I have a Private messaging system using PHP and mySQL with notification. The database
We have PHP 5.2.6 deployed to c:\php and in that folder there is the
in my php script that sends a push notification to iPhone, I have the
I have a complete automatic notification system running on my web page, that is
I'v built a application using codeigniter and I have a message system that displays
I have an ajax heavy web-application built using PHP, jQuery. I am looking for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.