JavaScript Bootstrap Modal and Badges

I have the following lines of code in my webpage - example/demo.

HTML:

<p data-toggle="modal" data-target="#messagesModal"><a target='_blank' href="#">Messages <span class="badge">2</span></a>
</p>

<!-- Modal -->
<div class="modal fade" id="messagesModal" role="dialog">
  <div class="modal-dialog">

    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Messages</h4>
      </div>

      <div class="modal-body">
        <div class="alert fade in">
          <a target='_blank' href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
          <strong>Message 01</strong>:
          <p>Lipsum Ipsum
          </p>
        </div>

        <div class="alert fade in">
          <a target='_blank' href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
          <strong>Message 02</strong>:
          <p>Ipsum Lipsum</p>
        </div>
      </div>

      <div class="modal-footer">
        <div class="col-md-8 pull-left">
        </div>

        <div class="col-md-4">
          <button type="button" class="btn btn-default pull-right" data-dismiss="modal">Close</button>
        </div>
      </div>
    </div>
  </div>
</div>

How can I update the badge to represent the correct amount of messages in the modal?

For example, when the user closes or removes a message in the modal, the badge will go from displaying the number 2 to 1?

Also, is it possible to display the text "There are no more messages." when all of the messages have been removed?

Answer:1

I have a table in html with only 1 column: My FILES. What I'm trying to reach: (a file explorer of a folder in the server) When the page loads in body onload i call an ajax function that add a row ...

I have a table in html with only 1 column: My FILES. What I'm trying to reach: (a file explorer of a folder in the server) When the page loads in body onload i call an ajax function that add a row ...

  1. ajax request getting cancelled chrome
  2. ajax request is getting canceled before it completes
  3. ajax request not getting response

I'm trying to incorporate a React component for radio buttons in my iOS app that's written in React Native, however I get an error when trying to import the component using the method that the author ...

I'm trying to incorporate a React component for radio buttons in my iOS app that's written in React Native, however I get an error when trying to import the component using the method that the author ...

  1. error in import statement in java
  2. import statement error in eclipse

I am trying to implement angular-translate in my application. So, I found the following JSFiddle which should demonstrate angular-translate, but I get the following error message: 'undefined' is ...

I am trying to implement angular-translate in my application. So, I found the following JSFiddle which should demonstrate angular-translate, but I get the following error message: 'undefined' is ...

On my server (written in Go), I'm sending back a custom header field that I'm trying to read from when I make an ajax call. $.ajax({ url: url, success: function(data, status, request)...

On my server (written in Go), I'm sending back a custom header field that I'm trying to read from when I make an ajax call. $.ajax({ url: url, success: function(data, status, request)...

  1. get response headers javascript
  2. get response headers
  3. get response headers angular 6
  4. get response headers curl
  5. get response headers python requests
  6. get response headers axios
  7. get response headers angular
  8. get response headers python
  9. get response headers fetch
  10. get response headers js
  11. get response headers c#
  12. get response headers php
  13. get response headers angular 7
  14. get response headers curl php
  15. get response headers java
  16. get response headers postman
  17. get response headers angular httpclient
  18. get response headers express
  19. get response headers angular 5
  20. get response headers jquery