I would like to hide the Carousel arrows and indicators if there is just one item

Is there a way to hide the next and previous arrows on images if there is only one image available? https://i.sstatic.net/vuAIc.png

<Col md={6}>
    <Carousel>
        {product.image ?  
            <Carousel.Item>
                <img
                className="d-block w-100"
                src={product.image}
                style={{width:'540px', height:'480px'}}
                />
            </Carousel.Item> : 

            <Carousel.Item>
                <img
                className="d-block w-100"
                src={product.image}
                style={{width:'540px', height:'480px'}}
                />
            </Carousel.Item>
        }

        {product.imageSecond ?  
            <Carousel.Item>
                <img
                className="d-block w-100"
                src={product.imageSecond}
                style={{width:'540px', height:'480px'}}
                />
            </Carousel.Item> : 

            null
        }

        // Additional image items check...

    </Carousel>
</Col>

I attempted to accomplish this using DOM manipulation, but I encountered an issue with the "class is undefined" error. Since I'm not very proficient in CSS and DOM scripting, any guidance on achieving the desired functionality would be highly appreciated.

The goal is to display arrows and bottom indicators for the carousel only when there are two or more images present. Thank you in advance for your assistance!

Answer №1

let imageElements = [...document.querySelectorAll('.d-block.w-100')]
if(imageElements.length === 1){
    let backArrow = document.querySelector('.carousel-control-prev-icon')
    let forwardArrow = document.querySelector('.carousel-control-next-icon')

    backArrow.style.hidden = true
    forwardArrow.style.hidden = true
}

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

Menu Table displaying errors in layout

I've been struggling to align the menu table to match the homepage, but so far I haven't had any success. It seems like the main index.php page is using its own CSS for some unknown reason. Check out lcrisq.com Here is the desired design: Take ...

Keeping React Component Synchronized with External Data Changes

Imagine a scenario in which my React application connects to an MQTT broker upon running, retrieving data that is then stored in an object structured as follows: var data = { shoeColor1: 'blue', shoeColor2: 'red' shoeC ...

Bootstrap 4 fails to adapt on mobile devices, causing columns to pile on top of each other

My website is optimized for desktop viewing, but I'm struggling to make it responsive on mobile using bootstrap 4. Even though my custom columns have always worked in the past, they are now overlapping on top of each other instead of stacking correct ...

Understanding how to utilize jQuery or prototype to interpret onclick event containing "setLocation(...)" can enhance the functionality

I am dealing with a specific tag: <button onclick="setLocation('http://mysite.com/checkout/cart/add/product/17/')" /> My goal is to trigger an ajax request when the button is clicked. I want to extract the URL segment "product/17" and app ...

Spin the SVG image upon clicking the Bootstrap 4 collapse feature

I am attempting to create a toggle effect for an SVG icon, rotating it from the up position to the down position when clicked. While a pure CSS solution would be ideal, I am struggling to implement it for an SVG icon. Unfortunately, I cannot use a font ic ...

conceal the starting and ending markers for text separators

Here are two different methods to tackle this issue: one using pure CSS and the other utilizing jQuery. These solutions will allow for any symbol or image to be used as a separator. Note: Creating and finding solutions for questions like these can be quit ...

The getServerSideProps function is failing to execute

This code snippet provides the implementation of my App Container: import { useEffect } from "react" import axios from 'axios' import { useSelector, useDispatch } from "react-redux" import { setUserState } from '../slices ...

Modify all CSS styles as soon as I incorporate the Bootstrap framework

<meta charset="utf-8"> <meta name="viewport" content="width=device-width"> <!--Supporting All devices width--> <meta name="description" content="Lowa State University Library"> <meta name="keywords" content="For a Web ...

Send information to the webpage through both GET and POST methods

Can data be submitted to the same page using both the GET and POST methods? Certain sensitive information needs to be sent via POST, while other data such as page_number and search_phrase should be submitted with GET. I attempted creating two forms, one ...

Is it accurate that JavascriptResult displays javascript on the page in a string format?

I am new to .NET MVC and have been experimenting with different return types in MVC. However, I am having trouble getting the JavaScriptResult to work. In my controller, I have the following code: public ActionResult DoSomething() { string s = ...

Steps to generate a range of years in a React Native application

I have successfully built a drop-down view for users to select their date of birth using dummy data. However, I am facing the challenge of implementing a data module for years/months/days using date-fns. Can anyone guide me on how to achieve this? So far, ...

Auto-layout malfunctions when .col contains a child .table-responsive

Utilizing Bootstrap's auto-layout grid allows for the explicit specification of width for select columns, with the remaining columns evenly splitting the space. However, when an auto-.col contains a child with .table-responsive, the system appears to ...

What makes (_=1)=>$=>_++ act as a tally?

One of my buddies encountered this question during a JavaScript job interview: Can you explain how this counter functions? In other words, what does the non-minified version look like? let Counter = (_=1)=>$=>_++ let c1 = Counter() co ...

The functionality of the JavaScript Array Map function is not meeting our expectations

I am encountering an issue with the Array.map function that is not behaving as expected. Below is a simplified example to help me understand where I am going wrong. Here is the code snippet in question: console.log(this.reportTestData) let data = this.rep ...

What are some strategies for stopping Knex.js from executing a query object upon return from an asynchronous function?

My node.js backend utilizes Knex.js to construct dynamic DB queries based on various inputs. The challenge I'm facing is handling asynchronous processing of certain inputs. When returning a knex query object from an async function or a Promise resolve ...

Python Quart having issues with HTML rendering accurately

When rendering a page in Python Quart (as a blueprint), I utilize the following code: return await render_template(self.TEMPLATE_LOGIN_PAGE) The issue at hand is that the error message is not displaying correctly. Here are the problems it's encounter ...

Updating the component's state based on the server response

Injecting the props into the initial state of a component is something I'm working on. The goal is to update the state and have the data reflected immediately when a button inside the component is clicked. The eventData object contains two attributes ...

Looking for a way to locate any elements in jQuery that do not contain a certain CSS class?

I am looking to target all form elements that do not contain a specific CSS class. For example: <form> <div> <input type="text" class="good"/> <input type="text" class="good"/> <input type="text" class="bad"/> ...

Transforming a JavaScript script into a functional plugin

I've been working on converting my script into a plugin (code provided below), but I seem to be missing something. Can someone help me figure out where I went wrong? The page isn't showing any errors, so it's hard to pinpoint the issue. ;(f ...

Convert all relative path URLs in images to absolute paths using either PHP, javascript, or jQuery

I am looking to transform any relative URL found on a webpage, with the main intention of resolving issues related to images not being displayed. The goal is to convert these relative URLs into absolute URLs. For example: From <img src="/folder/folder ...