Search code examples
jqueryjquery-ui

How do i limit the amount of LI in using jQuery


I'm using the jQuery UI to develop a drag and drop favourites UI, I want to limit the amount of LI's (limited to 5) dropped in a specific region, and replace current ones if a user drop one over the other. How can this be done? I'm currently using a modified version of the photomanager on the jQuery UI site.


Solution

  • You can check how many LI's are in the region and from 5+ you replace the actual LI's. Lets see:

    On Drop event:
       if($("#region li").length<5){
          //do your normal drop handling
       }else{
          //replace one of the actual li's with the dragged one
       }
    

    is that helpful?