Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Adding a button for the end of the ul list

In my asp.net MVC application, I’m using signalR for push notifications.

There I load the notifications to the ul list like this.

 <ul class="nav navbar-nav navbar-right">
   <li role="presentation" class="dropdown open">
     <a class="dropdown-toggle info-number" data-toggle="dropdown" aria-expanded="false" onclick="LoadData();">
       <i class="fa fa-envelope-o"></i>
       <span class="badge bg-green" id="notiCount">0</span>
     </a>
     <ul id="menu1" class="dropdown-menu list-unstyled msg_list" role="menu"></ul>
   </li>
 </ul>

So I check the notifications and shows in the dropdown from javascript

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

function LoadData() {

  $('#menu1').empty();
  $('#menu1').append($('<li> Loading.. </li>'));
  $.ajax({
    type: 'GET',
    url: $("#Get").val(),
    dataType: 'json',
    data: {},
    success: function (data) {
      if (data.Success == true) {

        $('#menu1').empty();
        if (data.listNoti.length == 0) {
          $('')
          $('#menu1').append($('<li>There is nothing to show </li>'));
          console.log("No Data");
        }
        $("#notiCount").empty();
        $("#notiCount").append(data.listNoti.length);
        $.each(data.listNoti, function (index, value) {

          $("#menu1").append('<li> <a> <span class=image><img src ="/Theme/production/images/Annon.png"/> </span> <span>' + value.Ndetails + '</li><hr/>');

        });
      }
    }
  });
}

I want to add a section that end of the <li> as a button to clear all notifications. How to add this?

I tried adding it inside the menu1 but when the javascript load the notifications it got removed.

>Solution :

Seems you just need to invoke append() out of each() to add the button

$.each(data.listNoti, function (index, value) {
  $("#menu1").append('<li> <a> <span class=image><img src ="/Theme/production/images/Annon.png"/> </span> <span>' + value.Ndetails + '</li><hr/>');
});
$("#menu1").append('<li><button onclick="removeEle()">Remove</button></li>')
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading