Conceal the galleryView plugin seamlessly without the need for a

I have implemented jQuery on my webpage to load content without refreshing, displaying only the necessary information. Within the gallery section, there are links for "Other Photography" and "Nude Art". Clicking on these links initializes the gallery with the respective pictures. However, once one of the galleries is initialized, there is no way to hide it to make room for the other.

To distinguish between the two galleries, I created two ul li lists with images using the same id for CSS, but different classes.

<div id="underage">
  <ul class="galleryShow">
    ...
  </ul>
</div>

<div id="adult">
  <ul class="galleryShow">
    ...
  </ul>
</div>

Here is the jQuery code snippet:

$('#galleryButton').click(function() {
                $('.mainBody').slideUp().ready(function() {
                    $('#gallery').slideDown(600).ready(function() {

                            $('#otherPhotoButton').click(function() {
                                /*$('.adult').hide();*/
                                $('.underage').galleryView();
                            });

                            $("#nudeButton").confirm({
                                text: "Are you over 18?",
                                confirm: function(button) {
                                    /*$('.undergage').hide();*/
                                    $('.adult').galleryView();
                                },
                                cancel: function(button) {
                                    window.location.href = "https://www.google.hu/search?q=puppies";
                                },
                                confirmButton: "Yes I am",
                                cancelButton: "No"
                            });
                        });     
                    }); 
                });

Answer №1

Unfortunately, the GalleryView plugin does not retain the ID when applied to elements.

To fix this issue, make a small adjustment to your HTML structure:

<div id="underage">
    <ul class="galleryShow">
        ...
    </ul>
</div>

<div id="adult">
    <ul class="galleryShow">
        ...
    </ul>
</div>

Below is the JavaScript code for your buttons that should now function correctly:

$('#otherPhotoButton').click(function() {
    if ($('#underage ul').length) {
        $('#underage ul').galleryView();
    }
    $('#underage').show();
    $('#adult').hide();
});
$('#nudeButton').confirm({
    text: 'Are you over 18?',
    confirm: function(button) {
        if ($('#adult ul').length) {
            $('#adult ul').galleryView();
        }
        $('#adult').show();
        $('#underage').hide();
    },
    cancel: function(button) {
        window.location.href = 'https://www.google.hu/search?q=puppies';
    },
    confirmButton: 'Yes, I am',
    cancelButton: 'No'
});

Answer №2

Avoid using identical ids, update the class and id attributes for your <ul> elements as shown below:

<ul id="underage" class='galleryShow'>
<ul id="adult" class='galleryShow'>

Additionally, modify all CSS references from #galleryShow to .galleryShow.

If you are using the galleryView library, it might be altering the HTML structure after initialization. Consider sharing a code example on a platform like JSFiddle for further assistance.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for transferring a dataTable from C# code behind to jQuery

I am trying to pass a string as a table of data from C# code behind to jQuery using two functions: C# [System.Web.Services.WebMethod(EnableSession = true)] public static List<ListItem> GetImageArray(string AccNo) { string result = string.Empty; ...

Enhancing Promises.all with extra parameters

Looking to dive into promises, eager to learn. Here is an array of shopIds I'm working with: let shopIdsArray = ['shop1','shop2','shop3']; Additionally, there's an external promise call: getProducts(shopId, ' ...

Tips for automatically selecting the state from a dropdown list when utilizing address autofill

I created an HTML form and noticed that Chrome's autofill feature successfully fills in the street address, city, and zip code. However, when I use a select/option dropdown list for the state input, it does not get auto-filled. I have tried using sta ...

Deactivate a few CSS guidelines

For my project, I am incorporating interfaces within other interfaces and have been facing conflicts between bootstrap rules and other CSS files. To address this, I encapsulated all Bootstrap rules within a .use_bootstrap class. Now, within my interfaces ...

Update the content of a div element with the data retrieved through an Ajax response

I am attempting to update the inner HTML of a div after a certain interval. I am receiving the correct response using Ajax, but I am struggling to replace the inner HTML of the selected element with the Ajax response. What could be wrong with my code? HTM ...

Issue with specific selectors causing React CSS module malfunction

Currently, I am a beginner in learning React and have been experimenting with CSS modules. Even though Menu.module.css is mostly functioning correctly, it seems to be having an issue applying styles to the .menu a.last selector for some reason (although i ...

How can you use jQuery's fadeToggle feature for a navigation bar to display and hide content individually?

Being a newcomer to CSS/Jquery, I apologize for the simplicity of my question. I have two navigation links: ABOUT and CONTACT. I've managed to get their content to fade in and out using fadeToggle. However, when one link is clicked after another, the ...

Tips on connecting a font directory from FontAwesome

I am currently attempting to incorporate the fonts provided by FontAwesome for their icons, and they specify that a root folder named Fonts is needed. My attempt to link it was using: <link type="text/css" href="/myPath/font" /> ...

Issue with Angular Material Mat Horizontal Stepper: Incorrect step selection when progressing with next button

I have a horizontal mat stepper that needs to be controlled using Next and Back buttons. The steps are generated using ngFor. I have created a variable called "stepIndex" which is bound to the "selectedIndex" input. The Next button should increment this va ...

Is it not feasible to place a well within a column using Bootstrap?

Would like to place a .well div (or a button, whichever works best) within the designated green area shown in this image: here Here is the code I currently have: <div class="container-fluid"> <div class="row row1" style=&q ...

difficulty generating a tooltip

Purpose: My main goal is to implement a tooltip feature where hovering over text triggers the display of a tooltip. To achieve this, I am seeking inspiration from an example on w3schools which can be found at this link. Current Implementation: render() { ...

jQuery draggable elements can be easily dropped onto droppable areas and sorted

I need help with arranging the words in the bottom tiles by sorting them from "Most Like Me" to "Least Like Me" droppable areas. Currently, I am able to drag and drop the words into different boxes, but it ends up stacking two draggable items on top of eac ...

Implementing a dynamic loading strategy for Google reCAPTCHA based on language selection

I have a unique application that requires the selection of one language out of four options (English, French, Dutch, español) in a form. Below the language selection, the Google reCaptcha is displayed. I am looking to dynamically load the reCaptcha scrip ...

How to use CSS to add a pseudo element to a table and position it outside of the parent's boundaries on the left

I am currently utilizing the "ag-grid" data-table library (along with Angular 2, although the framework is not crucial) which highlights a selected row (using the default class .ag-row) by adding the class .ag-row-selected to it. Each row contains numerous ...

Update the promise status to reflect any changes

While attempting to modify the button text based on the promise status, I created a custom directive for this purpose. Below is the code snippet for my custom directive: .directive('myDir',function(){ return { scope: { ...

The code in check.js causes a square of dots to emerge on the screen in Skype

Trying to add a Skype call button to my page has been successful, but there's one issue - a pesky white dot keeps appearing at the bottom of the footer. The script source I used is as follows: <script src="http://download.skype.com/share/skypebu ...

Update the value of a scope variable directly within a controller. Subsequently making a function call

Hey there, I just want to start by saying sorry in case this question has already been asked or if it seems silly. I'm pretty new to AngularJS and have managed to overcome CORS errors, set up login via Parse, and even created an API for my app using ...

What seems to be the problem at hand, and where exactly is the issue located?

import React from 'react'; const card = ({name, email, id}) => { return( <div className='tc bg-light-green dib br3 ma2 grow bw2 shadow-5'> <img alt="robots" src = {'https://uniqueimage. ...

Evaluating the conditional rendering of a React child component using Jest and Enzyme

I am currently working on expanding the test coverage for this particular file: import React, { useContext } from 'react'; import UserContext from '../../contexts/user'; import styles from './index-styles.scss'; const UserLog ...

Is there any need for transpiling .ts files to .js when Node is capable of running .ts files directly?

If you are using node version 12, try running the following command: node hello.ts I'm curious about the purpose of installing typescript globally with npm: npm install -g typescript After that, compiling your TypeScript file to JavaScript with: ...