Search code examples
jqueryjquery-masonry

Jquery: masonry('hide',element) method with a jquery element


So, I'm using Masonry to make a "fluid" layout in my site but now I've encountered a problem involving its hide and reveal methods.

In an event, I'm making this call:

$container.masonry('hide', $(this));

As you can see, I'm using $(this) to tell masonry what element to hide through jquery

But apparently, this method does not work with a jquery element?

The error message in my console looks like this:

Uncaught TypeError: Object #<HTMLElement> has no method 'hide' (masonry.pkgd.min.js:9)

I tried looking in the documentation but all it says about the accepted type is:

$container.masonry( 'hide', items )

items Type: Array of Masonry.Items

What is a Masonry.Item supposed to be? And how do I indicate my element as one?


Solution

  • If you read the documentation then you find items are the array of elements.

    items Type: Array of Masonry.Items

    Try this,

    var arr=new Array();
    arr.push($(this));
    $container.masonry('hide', arr);