Manipulating list items with jQuery

I am currently trying to manipulate an unordered list with jQuery, essentially I have a list of links in an unordered list, some users have access (all installed servers) to certain files / pages.

I was hoping to use some jQuery to remove multiple list items from the DOM, simply because I no longer wanted the user not to click on the link, load the page, and then display an error because she didn't have enough access.

I already have an object setup and successfully removed one offline reference from the DOM, although I can't seem to get the selector to remove list items correctly.

HTML list:

<div id="browse" class="bubble"> 
<blockquote>
<ul id="browses">
<li><a href="browse.php?id=15" class="browse">Access</a><br /></li> //trying to remove
<li><a href="browse.php?id=1" class="browse">Accounts</a><br /></li> //trying to remove
<li><a href="browse.php?id=2" class="browse">Browse's</a><br /></li> //trying to remove
<li><a href="browse.php?id=7" class="browse">Commands</a><br /></li> //trying to remove
<li><a href="browse.php?id=4" class="browse">Content</a><br /></li>
<li><a href="browse.php?id=8" class="browse">Logs</a><br /></li>
<li><a href="browse.php?id=10" class="browse">Sessions</a><br /></li>
<li><a href="browse.php?id=11" class="browse">Settings</a><br /></li> //trying to remove
<li><a href="browse.php?id=12" class="browse">Sites</a><br /></li> //trying to remove
</ul>   
</blockquote>
<cite>Browse and manage the currently active sites data</cite>
</div>

      

Object so far:

Session = function(){
    this.init(phpdev_session);
}

$.extend(Session.prototype, {
    // object variables
    vars: '',

    init: function(phpdev_session){
        // do initialization here
        this.vars = phpdev_session;
    },

    restrict: function() {
        if (this.vars.account_class == '40') {
            //access client or less, remove manage another site link and a few browses from #browse ul
            //note: its all restricted server side, so its just a presentation layer.
            $('a#activate').remove();
            $('#browses').remove('li:eq(0)').remove('li:eq(1)').remove('li:eq(2)').remove('li:eq(3)').remove('li:eq(7)').remove('li:eq(8)');
        }
    }
});

$(document).ready(function() {
    var session = new Session(phpdev_session);
    session.restrict();
});

      

0


source to share


1 answer


I don't think jQuery is the right tool for this (I would do it server side), but I would add the server side of the class to the elements they don't have access to, and then just

$(".noAccess").remove();

      



If you are going to do this, just remove them server side as you will have the code.

+4


source







All Articles