Display one item at a time and allow the option to skip

I am trying to display only one task at a time. When the user clicks on "skip", the next task should be shown. This could range from a list of 3 tasks to a list of 30 tasks.

So how can I display only one task at a time?

$("a#skip").click(function() {
    $('#id_task_{{i.id}}').hide('slide', { direction: 'left' }, 400);
}; 

<div id="reload">
    <div class="task" id="id_task_1">
        <a href="link to task" class="image">
            Task 1
        </a>
        <a class="skip_class" id="skip">Skip</a>
    </div>
    <div class="task" id="id_task_2">
        <a href="link to task" class="image">
            Task 2
        </a>
        <a class="skip_class" id="skip">Skip</a>
    </div>
</div>

Check out this Fiddle for a better understanding of what I'm working on. Thank you for your assistance.

Answer №1

This snippet of code demonstrates how to toggle classes in jQuery

// Applying a hide class to task divs on page load

$(".skip_class").click(function () {
    var $currTask = $(this).closest('.task');
    // Display the next task
    $currTask.nextAll('.task').first().removeClass('hide');
    // Conceal the current task
    $currTask.hide('slide', {
        direction: 'left'
    }, 400);
});

View Demo on Fiddle

Answer №2

To display only the first task and reveal the rest on click, you can use CSS:

.task {
   display: none;   
}
#reload .task:first-child {
   display: block;   
}

...

$("a.skip_class").click(function() {
   var task = $(this).parent();
   task.hide();
   task.next().show();
   if(task.next().attr('id') === undefined) {
     task.parent().children('.task:first').show();   
)};

http://jsfiddle.net/fAszU/1/

Also, as suggested by @Sushanth, don't forget to include the jQuery effects core plugin for the slide effect.

Answer №3

Check out this live example on JSFiddle: http://jsfiddle.net/rGvna/14/

One approach could be to add a data attribute to your .task elements that specifies the corresponding page number.

<div id="reload">
    <div class="task" data-task-num="1">
        <a href="link to task" class="image">
            Task 1
        </a>
    </div>
    <div class="task" data-task-num="2">
        <a href="link to task" class="image">
            Task 2
        </a>
    </div>
    <div class="task" data-task-num="3">
        <a href="link to task" class="image">
            Task 3
        </a>
    </div>
    <div class="task" data-task-num="4">
        <a href="link to task" class="image">
            Task 4
        </a>
    </div>    
</div>
<a class="skip_class" id="skip">Skip</a>

Then, using jQuery's show() and hide() methods, you can cycle through the tasks like this:

var starting_task = 1;
var last_task  = 4;
var skip_to_task = function(task_num) {
        $('.task').hide();
        $('.task[data-task-num=' + task_num +']').show();
        if (task_num < last_task) {
            $("#skip").data('target-task', task_num + 1);    
        }
    };

skip_to_task(starting_task); // start with the first task

$("#skip").click(function(e) {
    var target_task = $(e.target).data('target-task');
    skip_to_task(target_task);
});

Answer №4

Is this solution effective?

$(document).ready(function(){
    $("a.skip_class").click(function() {
        $(this).parent().hide();
        $(this).parent().next('.task').show();
    });
});  

http://example.com/code-sample

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

How can jQuery incorporate additional selection criteria for a parent element?

How can I apply a specific criteria to a node that has been selected using jQuery? let objDIV = $("#selindividual").parent(); After retrieving the DIV, I want to target the following: button:contains(\"Submit\") If I had to do this in ...

Tips for setting background colors as a prop for Material UI cards in React JS

Currently utilizing the Material UI next framework to construct a wrapper for the card component. This customized wrapper allows for personalization of the component. I have successfully extended the component so that the title and image within the card ca ...

How can I prevent this parsing error from happening? Implementing JSON with double quotation marks

In the JSON string object, we typically have properties and their corresponding values formatted as "Property":"Value". However, if the value itself contains a double quote, such as in the example "Property": "my country is "uk"", this can result in a par ...

Tips on utilizing the event.preventDefault() method within AngularJS?

Recently, I stumbled upon a technique to prevent page refreshing after submitting a form by using event.preventDefault();. As someone who is still learning Angular, I am unsure of how to incorporate this syntax into my Angular controller. Is "event" some s ...

Calculating cumulative sums in a MongoDB query

Within my database, I store activities that span across different periods, starting on one day and ending on another. Here's an example document: { "activity" : "test", "period" : [ ISODate("2020-01-01T00:00:00Z"), ISODate("2020-02-10 ...

Using Yii2, create a button with an onclick event that executes a JsExpression

I need to submit a form with an array of elements whose number is unknown. class DynamicForm extends Model { /** var string[] */ public elements[]; } In the view where the form submission takes place, I want to include a button that triggers a Ja ...

Trigger an animation function with JQuery once the first one has finished

I am attempting to create a step-by-step animation of a div in JQuery. Each animation is triggered by a click, followed by a double-click, and so on. My issue arises when the animations overlap. When I double-click the div, both the first and second anima ...

The issue with VS Code is that it is running the wrong file instead of

Whenever I try to run my Python file, it keeps opening the previous HTML file instead. Despite clicking "run" on my Python file in VS Code, the terminal is not executing (as it normally does), and instead VS Code continues to open the previously opened HT ...

blocks that adapt to different screen sizes, in addition to the

My primary DIV has the CSS properties {width:100%; max-width: 900px} applied. I am looking to add an additional DIV that aligns with the left free space and another that aligns with the right space, all without using Javascript. Is this possible and if so ...

Create a Cutting-edge Navbar in Bootstrap 5.1 Featuring Three Distinct Sections: Left, Center, and Right

I'm encountering challenges with formatting the navbar layout I am currently designing. My goal is to create a navbar with three distinct sections as outlined in the title. In the first section on the left, there should be an image and a button-like ...

Exploring the potential of Oracle Openscript in combination with Javascript using AngularJS,

I have encountered an issue while using Openscript on a form page with a clickable "save" button implemented as a div. Manually clicking the button triggers a javascript event that saves any changes made on the page. However, when I run the script, the but ...

Personalize your hr tag

https://i.stack.imgur.com/9lumC.png Is there a way to create an hr line that looks exactly like the image above? I attempted using clip-path: polygon(0 20%, 0 100%, 100% 100%, 100% 0%, 5% 0) but it didn't work .divider { color:#1D0000; ...

I'm having trouble obtaining accurate results for $....<...$ within the <li> tags using MathJax

I have gained extensive experience working with LaTeX formatting, but not every document follows the standard practice of having a space before and after the symbols < and >. When I attempt to use MathJax to display these documents, they fail to rend ...

SCSS - Hide div1 when div2 is hovered over

In an attempt to make a div disappear when hovering over another div using only CSS, I have set up two divs: <div class="" id="target">I will disappear</div> <div class="hover_box">Hover me</div> Here is my SCSS code: #target { ...

What is causing the div to expand even though css max-width is applied?

I am currently facing an issue with the navigation on mobile view while using Bootstrap 4. Specifically, the .nav .dropdown-menu and .text-truncate classes are not displaying ellipsis when the content text length is too long. I have attempted to resolve t ...

Utilizing jQuery's .fadeOut and .fadeIn for seamless transitions in webpage designs

My issue involves using simple jquery to display images based on category selectors being clicked (subpar code snippet) $(".graphic-design-selector").click(function(){ $(".web-design, .photography").fadeOut(1000); $(".design").fadeIn(1000); }); ...

Determine the row ID of the selected radio button

I have a function that generates a table inside a modal popup, and the table is filled with data from an array received through an ajax call. Now, when a button in the modal popup is clicked, I need to retrieve the value of item.TimedPathwayID associated w ...

Making the text gradually disappear at the bottom of a section using a see-through overlay, while ensuring the height remains within the boundaries of the section even

Trying to achieve a sleek fade-out effect at the end of a text section for a 'read more' indicator. I've been studying various tutorials, including this, and my current code is as follows: html <section> <p>Lorem ipsum dol ...

Initiating an AJAX request to communicate with a Node.js server

Recently, I started exploring NodeJS and decided to utilize the npm spotcrime package for retrieving crime data based on user input location through an ajax call triggered by a button click. The npm documentation provides the following code snippet for usi ...

Is it feasible to utilize VAST for delivering HLS streams? Can m3u8 files be incorporated into VAST tags for delivery?

We are integrating a video player that supports VAST pre-roll, mid-roll, and post-roll video ads. I'm wondering if it's feasible to include m3u8 files in VAST tags? I've reviewed the vast specification and examples, but haven't come ac ...