Skip to content
Advertisement

Moving image to first position after hide other elements

I need your help. When I fillter my image gallery and choose image that is on the second, third … etc position, image is static, doesn’t change position to the first from the left dynamically. ( see screen )

My code:

product_gallery.html

JavaScript

style_gallery.css

JavaScript

gallery_button.js

JavaScript

And here is the screen showing what’s wrong :

enter image description here

Advertisement

Answer

Your code is pretty close to working, if I remove the grid class (on the thumbnails div) it would produce your desired behavior without any additional modifications, but you most likely want the grid behavior.

Even though you’re hiding the img elements, their parent elements (a anchor elements) are not hidden. You should be able to hide/show the parent elements of the images (the a anchor elements) to get your desired behavior.

As you can see from the modified js below, it’s just one extra .parent() call that was adjusted on your show/hide selectors:

JavaScript

Just one additional suggestion for future questions: typically it’s a lot easier for people to answer you question + see what you’re seeing by using the built in Javascript/HTML/CSS snippet tool built into StackOverflow (for images you can use something like the placeholder site I used below).

JavaScript
JavaScript
JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement