How to implement Favorites on localStorage?

Asked

Viewed 140 times

1

I’m implementing a notification control project. On the page where you list notifications, there is a star in each notification to add it to your favorites, which is stored in the localStorage. However, I am not able to program jQuery to receive class status and store. It follows code.

index.html

<script type="text/javascript">

                 contador = localStorage.getItem("contador");

                 for(j=0;j<contador;j++)  
                 {    
                     d = localStorage.getItem("ntime-"+j);
                     data = $.datepicker.formatDate('dd/mm/yy', new Date(d));

                     document.write('<div class="list-group-item unread">'
                      +'<div class="list-left">'
                        +'<label class="ckbox">'
                        +  '<input type="checkbox" id="checkbox"><span></span>'
                        +  '<input type="hidden" class="nid" value="'+localStorage.getItem("nid-"+j)+'">'
                        +'</label>'
                        +'<span class="markstar"><i class="glyphicon glyphicon-star"></i></span>'                
                      +'</div>'
                      +'<div class="media">'                                    
                        +'<div class="media-body">'
                          +'<span class="pull-right">'+data+'</span>'
                          +'<h5 class="media-heading">Portal NetSorte</h5>'
                          +'<h5>'+localStorage.getItem("ntitulo-"+j)+'</h5>'
                        +'</div>'
                        +'<p>'+localStorage.getItem("nmensagem-"+j)+'</p>'
                      +'</div>'
                    +'</div>');

app js.

$('.markstar').on('click', function()
    {         
        var elem = $('span').hasClass('starred');

        if(elem)
        {
            alert("Possui starred");
        }
        else
        {
            alert("Não");
        }
 });
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.