Arrows on the button are unresponsive and there seems to be an incorrect number of

I've been working on a project by combining various examples I found online. I'm puzzled as to why it's displaying all the buttons at once instead of just one per page, and why the number of visible buttons decreases by one with each right click. Additionally, clicking the left arrow results in a blank screen.

If you click the right arrow after clicking the left arrow, you get stuck on a page with only one button, while the left arrow still shows a blank screen.

The goal is to have only one button on the screen at a time and be able to switch between different buttons using the right and left arrows. This is for an idle mine game.

Answer №1

Understanding the functionality of your code is crucial... It seems that the jQuery component is applying the class hide to certain list items for hiding and removing it from others to display them.

1] Initially, all buttons are visible because none of the items have the hide class applied to them. To fix this, either add the attribute class="hide" to all list items in HTML or create a JavaScript function to run on page load.

2] To address the inconsistent behavior of the left & right buttons, compare the jQuery functions as they are not performing identical operations. Align the left button's operation with the right one for consistency.

For the right button:

arrowRightCount = arrowRightCount + 3;
arrowLeftCount = arrowLeftCount - 3;

For the left button:

arrowLeftCount = arrowLeftCount - 3;
arrowRightCount = arrowRightCount - 3;

3] If you intend to display only one button, adjust the value from 3 to 1 in the jQuery script to ensure only one button is displayed.

Tip: Use distinct names for buttons to easily identify which button is currently displayed and its sequence.

Update: Although not extensively familiar with jQuery, the code can be simplified.
Review the updated jQuery, where the specific list items are targeted for adding/removing classes instead of all items. The modification now applies actions only to the prev/next elements based on the counter (cntr) to determine the current position.
Refer to this jsfiddle link for the output.

var mincount = 0; 
var maxcount = 10;
var cntr = 0;
$(document).ready(function() {

  // RIGHT ARROW
  $(".step-box .arrow-right").click(function(e) {
    if(cntr >= mincount && cntr < maxcount){
      $("#mines > li:eq(" + cntr + ")").addClass('hide');
      cntr = cntr + 1;
      $("#mines > li:eq(" + cntr + ")").removeClass('hide');
    }
  });

  // LEFT ARROW
  $(".step-box .arrow-left").click(function(e) {
    if(cntr > mincount && cntr <= maxcount){
      $("#mines > li:eq(" + cntr + ")").addClass('hide');
      cntr = cntr - 1;
      $("#mines > li:eq(" + cntr + ")").removeClass('hide');
    }
  });

});

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

Integrating individual script into HTML

Imagine you have a file named public/index.html. Additionally, there is another html file called otherScript, which contains only <script> tags with a script inside. How can you include these scripts into your public/index.html file? You intend to ...

What is the best way for me to insert a paragraph between two lists?

Is it possible to insert a paragraph in between lists even though it's not allowed? Here is an example of the code: <ol> <li>One</li> <p>Paragraph 1</p> <li>Two</li> <p>Paragraph 2</p ...

Reiterating the text and determining the length of the string

Currently, the script is capable of calculating the width of the script based on user input and can also determine the width of a string. However, I am facing an issue when attempting to repeat a string entered by the user. For example, if the user input ...

Trouble with ScrollView not scrolling on Nativescript-Vue

I am facing an issue with a scrollable view in my project. I have a list of items that should be scrollable, but for some reason it is not scrolling as expected. The structure involves a vertical stack layout wrapped in a scrollview, and inside the stackla ...

Sending an HTML form data to a Node.js server

I'm currently working on a simple project that involves creating a web form and sending it to node.js in order to save the information received. I've been following some YouTube tutorials (https://www.youtube.com/watch?v=rin7gb9kdpk), but I' ...

Having trouble getting getStaticProps to display JSX in Next.JS

I'm currently facing an issue with rendering basic data from a locally hosted Strapi API in my Next.js project. Although the data is successfully logged in the console, I am unable to map it into JSX. Below is the API get function: export async func ...

redux reducer returns an empty array after applying filter to the state

In my React component, I am utilizing Redux to manage the state. Since I am new to Redux, I have encountered some challenges with one of the reducers I created. One of the methods in my component involves making an HTTP request and then dispatching the dat ...

Tips for customizing the selection tip of a custom cursor using CSS

I have integrated a color picker jquery plugin on my website to allow users to pick colors from an image. I made a modification in the CSS to change the cursor to an eyedropper icon. However, currently when clicking on the image, the color pointed by the u ...

Error: The value of 'id' cannot be assigned to an undefined property

Recently, I've been delving into learning JS Express and decided to create a basic solution to handle GET / DELETE / POST / PUT requests. Everything was running smoothly until I encountered an issue with the POST router. Below is the code snippet for ...

Hacking through external script injections into the browser

Curious about how certain software or programs are able to inject html,css,js into a web browser without the need for installing any extensions. Every time I open Chrome or Firefox, I'm bombarded with ads on popular sites like Google homepage, Faceboo ...

Creating unit tests for linked functions in Node.js using Jest

Hey there! I'm looking to test a function using Jest that involves token verification and requires 3 parameters. Here's the code for the function: const verifyToken = (req, res, next) => { // Checking for token in header or URL parameter ...

Ensure the validation of numerous input fields within a single form with the use of Vue 3 composition API

Within my application, I have implemented custom validation and validators to ensure the accuracy of various form fields. The submit button functionality is designed to remain disabled until all input fields are filled. The creation of validators involves ...

The issue I am facing is with the post_logout_redirect_uri not functioning properly when using localStorage in an OIDC Auth

authority: 'yyy', client_id: this.'yyy', redirect_uri: 'http://localhost:4200/login', response_type: 'token', scope: 'yyy', post_logout_redirect_uri: & ...

Using jQuery to create a "read more" feature that shortens lengthy paragraphs based on word count rather than character count

Goal Shorten lengthy text to six words, then display "...show more" Implement a way to collapse the text back after expansion Overview The objective is to truncate the text and provide a link for expanding it with a "read more" option. The cutoff shou ...

"Is there a way to verify the existence of checkbox array values within a database using PHP Laravel

In order to display checkboxes for each country that exists in the database, I need to verify if the countries in the database match with those in the list. Since the values are retrieved directly from the database and can't be set as input values due ...

Button on aspx page not functioning properly when clicked

I seem to be experiencing an issue with buttons. To check if the function is being triggered, I used alert("") and found that it does enter the function when the button is clicked. However, after the alert, any other code inside the function seems to not w ...

Analyzing a JSON Structure Containing Numerous Sub-Objects

<script type="text/javascript" src="http://static.stackmob.com/js/2.5.3-crypto-sha1-hmac.js"></script> <script type="text/javascript"> $j.ajax({ dataType : 'json', url : "/api/core/v2/groups/", //or any other res ...

Gathering information from various web pages simultaneously without the need to manually navigate through each page using a webdriver

I'm new to the world of web scraping and I've successfully developed a program that allows me to extract specific, dynamic data by utilizing the selenium web driver. My current project involves scraping data from a FAQ page in order to gather in ...

What are some strategies to avoid render-blocking when CSS is loaded through HTML Imports?

I am in the process of developing a website using Web Components and Polymer, with assets being loaded through HTML Imports. This is an example of my markup: <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8> < ...

Issue with AngularJs: $http post only posting single item to collection inside a for loop

I have a collection that requires me to post multiple items in a for loop. Below is the code snippet: for(i = 0; i < 28; i++) { var request = $http({ method: "post", url: "/students", ...