Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8666965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:51:29+00:00 2026-06-12T17:51:29+00:00

Trying to create a clickable event so that when #next is clicked the html

  • 0

Trying to create a clickable event so that when #next is clicked the html in this case 2000-2001 etc is sent to a class on the body tag with an underscore eg. body class=”_2000-2001″.

The current date has the class selected and every time #next is clicked the selected class moves to that a tag.

What I need to figure out is how to get the next li a tag in the list on every click instead of the ul#dates li a.selected.

Should I use the .next() function?

<ul id="dates">                 
    <li><a href="#1970-1974" class="selected">1970-1974</a></li>        
    <li><a href="#1974-1980">1974-1980</a></li>         
    <li><a href="#1980-1992">1980-1992</a></li>         
    <li><a href="#1992-2000">1992-2000</a></li>         
    <li><a href="#2000-2001">2000-2001</a></li>     
    <li><a href="#2001-2004">2001-2004</a></li>         
    <li><a href="#2004-2006">2004-2006</a></li>         
    <li><a href="#2006-2007">2006-2007</a></li>         
    <li><a href="#2007-2008">2007-2008</a></li>         
    <li><a href="#2009-2011">2009-2011</a></li>     
    <li><a href="#Present">Present</a></li>
</ul>

<a href="#" id="next">+</a>
<a href="#" id="prev">-</a>

JQuery:

$('a#next').click(function() {
    var htmlStr = $('ul#dates li a.selected').html();
    console.log(htmlStr);
    $('body').attr('class', function() {
        return '_' + htmlStr;
    });
});

$('a#prev').click(function() {
    var htmlStr = $('ul#dates li a.selected').html();
    $('body').attr('class', function() {
        return '_' + htmlStr;
    });
});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T17:51:30+00:00Added an answer on June 12, 2026 at 5:51 pm

    Change

    $('ul#dates li a.selected').html();
    

    to

    $('ul#dates li a.selected').parent().next().children().html();
    

    Working fiddle.

    EDIT: With the “ul#dates li a.selected” selector we have selected the anchor tag inside the li element. So you have to move up one step by using parent() call and next() takes you to the next li element. Because you want the html of the child element we call $.children().html();. If there are multiple element inside li, you will have to do somthing like $.children().first().html();.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a drop down that will be something like this:
I am trying to create an object that can have clickable text within it.
I am trying to create a specific aspx page where I display clickable links
Trying to create a background-image slideshow and am getting this error... This is the
I am trying to create an experiment involving a series of clickable images where
I'm trying to delegate a click event to a TR element that contains a
I am trying to make the images clickable so that when they are pressed
I am trying to create an automation to perform some action to a HTML
I am trying to create a button using Actionscript. The only class which I
I'm trying to create a web page with a transparent image that appears overtop

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.