I am struggling to get the buttons to function properly

I'm working on creating a page with 2 questions and yes/no buttons using jQuery. I've implemented jQuery fade in/out effects for this purpose. However, the buttons don't seem to be functioning as expected. Could someone lend me a hand here??

I've provided all the code snippets of my page including CSS and jQuery.

jQuery:

   $(document).ready(function () {
        $(".qusone").click(function () {
            $(".one").fadeOut(100);
            $(".two").delay(100).fadeIn(100);
        });

        $(".qustwo").click(function () {
            $(".two").fadeOut(100);
            $(".three").delay(100).fadeIn(100);
        });
        
        // More jQuery functions go here...
    });

CSS:

* {
    margin: 0;
    padding: 0;
}
body {
    font-family: sans-serif;
    background: #EEF3FA;
    text-shadow: none;
}
// More CSS styles go here...

HTML:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

    <header>
        <div class="main head fix">
            <h1>Message</h1>
        </div>
    </header>

    // HTML content goes here...

    <footer>
        <div class="main">
            <p class="fotter">copyright 2013 <a href="#">Terms</a> 
                <a href="#">Privacy</a>
            </p>
        </div>
    </footer>

Check out the live demo on Fiddle

Answer №1

If you need to bind hidden buttons, I recommend using the following format:

$(document).on('click', '.qustwo', function() { ...add your code here... });

This method should solve the issue.

Answer №2

Consider replacing your current script with the following revised version:

$(document).ready(function () {
            $(".btn-one").click(function () {
                $(".section-one").fadeOut(100);
                $(".section-two").fadeIn(100);


            });

            $(".btn-two").click(function () {
                $(".section-two").fadeOut(100);
                $(".section-three").delay(100).fadeIn(100);

            });
            $(".btn-three").click(function () {
                $(".section-three").fadeOut(100);
                $(".full-section").delay(2200).fadeIn(100);

            });

            $(".btn-four").click(function () {
                $(".full-section").fadeOut(100);
                $(".section-four").delay(100).fadeIn(100);

            });

        });

It's recommended to further optimize your code for better execution.

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 incorporating a personalized touch to your radio buttons

Is there a way to customize the appearance of radio buttons in React or HTML elements, such as the screenshot below? I want to maintain the display of the number No.01 followed by the label next to it. If you have any suggestions or solutions, please shar ...

``Are you experiencing trouble with form fields not being marked as dirty when submitting? This issue can be solved with React-H

Hey there, team! Our usual practice is to validate the input when a user touches it and display an error message. However, when the user clicks submit, all fields should be marked as dirty and any error messages should be visible. Unfortunately, this isn&a ...

"Integrating Laravel 5.4 Backend with Angular 5 Frontend: A Step-by-Step

Currently, I am immersed in a project that involves creating a frontend using Angular 5 and backend business logic using Laravel 5.4 with MySQL Database. As someone new to this technology stack, I find myself grappling with establishing the data flow conne ...

Add a new external link to the Jquery Mobile webpage

Hello, I'm primarily a designer and my programming skills are quite limited. I am attempting to embed an external page into my jQuery Mobile webpage using external links, which works well in Safari. However, the issue arises when I save the web app t ...

Is there a way to efficiently update multiple objects within an array using just one operation in MongoDB?

Below is the structure of an Order document that I am working with: "order" : { "id": 999, "products" : [ { "id": 1, "price": 12.344746 }, { ...

What is the best way to group an array based on a dynamic key?

My goal is to group values in an array by a given ID. I've attempted a method for this, but it's not working for dynamic keys. Here is the current array: let employees = [{"employeeDetail": [{"empID": "XXYYZZ11"," ...

Revitalizing and rerouting page upon button click

The issue at hand is: When the "Post now" button is clicked, the modal with the filled form still appears. If the button is clicked again, it adds the same data repeatedly. I aim to have the page refresh and navigate to a link containing the prediction d ...

What is the best approach for deleting an element from an array based on its value

Is there a way to eliminate an element from a JavaScript array? Let's say we have an array: var arr = ['three', 'seven', 'eleven']; I want to be able to do the following: removeItem('seven', arr); I researc ...

Tips on destructuring an object property from a Pinia getter that may return an object based on a condition

I obtained this particular Store: export const useMyStore = defineStore('myStore', { state: () => { return { openTransOnly: false, keyword: '', openTransStatus: { nextPage: 0, complete: false }, pastDueT ...

When I try to reload the page, JavaScript ceases to function

Check out this JavaScript code snippet: var input = document.getElementById("password_field"); input.addEventListener("keyup", function(event) { if (event.keyCode === 13) { event.preventDefault(); document.getElementById("l ...

Oops! Looks like there was a hiccup in processing your query. Please review the MySQL manual for guidance on fixing the SQL syntax error

After being pressured to update to MySQL 5 and PHP 5 due to my service provider no longer supporting older versions, I encountered a problem with my MySQL search. The query was functioning properly on the server, but when included in the user's listin ...

What is the best way to update the content of a div using a variable within a function in AngularJS?

I have a dilemma with my HTML pages. The index.html page displays product information from a JSON file, and I want the details of a specific product to show up on detail.html when users click on it. Though an alert can display the details, the innerHTML of ...

Rearranging anchor tag order with the power of JQuery

Imagine I have five anchor tags <a id = "A" class = "Home">Home</a> <a id = "B" class = "Maps">Maps</a> <a id = "C" class = "Plans">Plans</a> <a id = "D" class = "Community">Community</a> <a id = "E" clas ...

How can the label value be updated in a material ui slider component?

code snippet: https://codesandbox.io/s/runtime-worker-kxse3?file=/src/App.js Can anyone help me ensure that the labels in the bubble display the same values as the text (3, 5, 7, 10)? ...

Adjust the quantity by clicking or typing

Hey there! How's it going? I'm curious to learn how I can enable the user to manually input the quantity in the field, in addition to using the plus and minus buttons. Essentially, is there a way for the user to type in the number of items they ...

What is the best way to make a Firestore request that relies on the initial Firebase response in Next.js?

Is there a way to perform a second cloud Firestore query using the uid obtained in the first query, without the second query executing before receiving the response from the first one? Here's my code: var {data} = useSWR('/api/report', fet ...

setTimeout is reluctant to introduce a delay when calling a method

I have a custom class that includes a method being used as an object. Upon clicking the element, this should trigger the method within the object. The first call is successful, however, I anticipated that the second call would have a delay of 75000 milli ...

Select specific columns from an array using Typescript

I have a collection of objects and I'm looking for a way to empower the user to choose which attributes they want to import into the database. Is there a method to map and generate a separate array containing only the selected properties for insertion ...

Creating an atom without any boundaries: A step-by-step guide

While browsing the Atom forum, I stumbled upon a post discussing scripts for enhancing the UI of Atom. I'm curious about where to place these scripts. Should they go in the Atom init script? Any guidance would be highly valued. Visit this link for m ...

Production environment sees req.cookies NEXTJS Middleware as undefined

Here is my latest middleware implementation: export async function middleware(request: NextRequest) { const token = request.headers.get('token') console.log(token) if (!token || token == undefined) { return NextResponse.redirect(new URL('/lo ...