Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery Masonry remove function example

I have implemented jQuery masonry to our site and it works great. Our site is dynamic and users must be able to add/remove masonry box's. The site has an add example but no remove example. Our db is queried returning x number of items. Looping through they are loaded and displayed. Here's a code sample: (we are use F3 framework and the F3:repeat is it's looping mechanism.).

<div id="container" class="transitions-enabled clearfix" style="clear:both;">
   <F3:repeat group="{{@productItems}}" value="{{@item}}">
      <div id="{{@item.itemId}}">
         <div class="box">
            <div class="view"> <!-- for css -->
               <a onclick='quickRemove("{{@item.itemId}}")>
                  <img src="{{@item.pic}}" />
               </a>
            </div>
            <p>
            {{@item.title}}
            </p>
         </div> 
      </div>
   </F3:repeat>
</div>

In the javascript code the item id number is unique and is passed into the function. It's also the div id# to distinguish each box. I've tried various combinations and methods but can't seem to get this to work.

function quickRemove(item){
    var obj = $('#'+item+'').html(); // item is the product id# but also the div id#
    $('#container').masonry('remove',obj);

    $('#container').masonry('reloadItems');
    $('#container').masonry('reload');
}

Has anyone out there successfully removed an item and how did you do it? Thx.

like image 957
user1760561 Avatar asked Jun 27 '26 19:06

user1760561


1 Answers

Currently you appear to be passing a string full of html to the masonry remove method. Pass it the actual jQuery wrapped element by not including .html()

function quickRemove(item){
    var obj = $('#'+item+''); // item is the product id# but also the div id#
    $('#container').masonry('remove',obj);

    $('#container').masonry('reloadItems');
    $('#container').masonry('reload');
}

Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!