executing JavaScript code within a div container

here's the code snippet I'm working with:

$(document).ready(function(){
$('#next').click(function() {
    $('.current').removeClass('current').hide()
        .next().show().addClass('current');
    if ($('.current').hasClass('last')) {
        $('#next').attr('disabled', true);
    }
    $('#prev').attr('disabled', null);
});

$('#prev').click(function() {
    $('.current').removeClass('current').hide()
        .prev().show().addClass('current');
    if ($('.current').hasClass('first')) {
        $('#prev').attr('disabled', true);
    }
    $('#next').attr('disabled', null);
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<!doctype html>
<html lang="en">
<head>
  <title>javascript problem</title>
</head>
<body>
  
<div id='div1' class="first current">
  <p>
    here the content of div 1
  </p>
  <button id="next">Start</button>
</div>;

<div id='div2'>
  <p>
    here the content of div 2
  </p>
  <button id="next">Next</button>
</div>;
  
  //then another 9 divs
  
<div id='div12' class="last">
  <input type="submit" value="submit" onclick="submit()">
</div>;

<div class="buttons">
<button id="prev" disabled="disabled">Prev</button>
<button id="next">Next</button>
</div>;
  
</body>
</html>

i am trying to have the buttons within each div and not at the bottom, so they do not appear at the end and i want to change their values on the first page. when i try this, the buttons stop functioning.

the code sample is not currently functional but it should show the next div when 'next' is clicked.

this is how i would like it to be presented:

<div id='div1' class='first current'>
<p>here the content of div 1</p>
<button id="next">Start</button>
</div>

hopefully that clears things up

Answer â„–1

It is important to remember that the id attribute in HTML should always be unique. Rather than using the same id for all your next/prev buttons, opt for a class instead. By doing so, you can easily bind the click event using the class, which will then apply to all elements with that class.

<button class="next">Start</button>

$('.next').click(function() { ... });

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

Validate user credentials with React Router Dom

In the process of developing a React application, I encountered an issue with the Header component. This specific component includes a Menu button that should toggle the sidebar and trigger a logout function, but only when the user is logged in. My approa ...

Click the button to trigger an AJAX request that sends the values from the forms within a while loop

Can someone help me figure out how to send input values through AJAX when a button is clicked? Below is my code. Appreciate any assistance. while { <form class="commentform"> <input type="hidden" class="proid" name="proid" value="<?= ...

Trouble with Ajax requests firing on document load in Firefox

When loading a JSP page in Firefox, I am invoking an AJAX function that calls a servlet. The servlet returns data in response. However, when I attempt to alert the data as shown in the code snippet below, I receive a null value. $.ajax({ url : 'S ...

How can I save the output of a function in a variable within an *ngIf directive and then utilize it within the same *ngIf block?

My scenario is as follows: I have a function that returns an array I need to conditionally render a component - only if the array exists and its length is greater than zero. The returned array should be passed as an @Input() to this component. Since t ...

Utilizing API data sharing across AngularJS controllers

I am facing a challenge with my parent controller and its children controllers, as I want them all to share the data fetched from an Api service. Controllers: var app = angular.module('mymodule',[]); app.controller('main', ['$scop ...

Use the reduce method to convert a JavaScript object from 2 to 1

Looking to create a function that can transform these objects: const input1 = [ { id: "lkhj68C13h8uWh4RJz7", post: "on XSS attacks", gender: "Littérature", postId: "cxTbP5EZjNCxw7rD60L7", }, { ...

waiting to display information until it is necessary

I am currently working on optimizing my website for improved loading speed and responsiveness. Users can scroll through up to 4k images, apply filters, and sort them based on their preferences. Below is the code snippet for my filtering function: function ...

Despite the fact that wp_mail is returning true, emails are not being received

Despite wp_mail() returning true, I am not receiving any emails that are submitted through the contact form on my WordPress blog. I even attempted to change the email address from Gmail to Hotmail with no success. Ajax code in the contact template $(&apo ...

customizing the appearance of a plugin

Visit the live site here. I am attempting to customize the text displayed in black under the Upcoming Events section. Despite multiple attempts using different combinations such as .vevent-item odd event-1 .description .event-time .event-label, I have not ...

The most efficient method of assigning array indexes to boolean values within an object

Struggling to determine the most efficient method of assigning array indices to an object with boolean values. Currently employing the following approach: let arr = [{t:1, te: "aa"}, {t:2, te: "aa"},{t:2, te: "aa"} ]; let obj ...

Dynamically alter routing in Express by retrieving route paths from a JSON document

My goal is to dynamically update my route in Express using a JSON file that stores the specific link. The JSON data resides in articles.js and appears as follows: title: 'title1', link: 'title2', creator: 'user1', crea ...

The jQuery fade speed effect has a limitation where it can only be utilized

When a specific link is clicked, I want a div to display with a fadeIn effect and then fadeOut when the link is clicked again. However, after the first click following an HTTP request, the fadeIn works but the fadeOut does not (the div closes though). More ...

Next.js is refusing to render an array of HTML elements

Consider this scenario where I have a block of code in TypeScript that attempts to create and display a list of elements. Here is a sample implementation: const MenuList = ():ReactElement => { const router = useRouter(), liElements:any = []; con ...

Exploring the world of JSON on the internet

Hello there! I'm currently working on a project similar to . However, I am facing difficulties when integrating my code with a discord bot. I am questioning whether it is possible to host JSON data online directly with the code snippet below: documen ...

Getting image blob data with Cropper Js in a Laravel controllerNeed help on how to get image blob data

I've been working with Cropper.js and Laravel. I managed to crop an image, put it into FormData, and send it to the Laravel controller using jQuery Ajax. However, I encountered a problem where I am not receiving any data in the controller, only an err ...

Route handler in Express for both admin and admin/* with identical routes

I am facing an issue where my admin/whatever URL is rendering the admin file, but when I try to access just "/admin" it shows a 404 error and does not go to that route. One solution could be creating a separate route for just "/admin," but I was wonderin ...

Learn how to use React.js props in your index.html file to

Issue: Unable to locate React props I am currently facing difficulties in accessing React props on the index.html page. This is the main page where I need to render meta tags properties that are fetched from the backend. I need to access my store data on ...

Styling with CSS: Enhancing list items with separators

Is there a way to include a separator image in my list using CSS? li { list-style: none; background-image: url("SlicingImage/button_unselect.png"); height: 53px; width: 180px; } This is the code for the separator image: url("SlicingImage ...

jqueryajax function returns a boolean value upon completion

Recently, I developed a container method to handle an ajax request: function postRating(formData) { $.ajax({ type: "POST", url: '/api/ratings', data: formData }) .done(function () { return true ...

Using query strings to manipulate the URL of an iframe and add additional information

I am facing a challenge with integrating my legacy perl application into an MVC application. I have set up a structure where the legacy application is loaded into an iframe within default.aspx, but I need to capture the URL of each page within the iframe a ...