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

  • SEARCH
  • Home
  • 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 9130199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:55:03+00:00 2026-06-17T07:55:03+00:00

I have some Javascript/PHP code that brings in a RSS feed in a kind

  • 0

I have some Javascript/PHP code that brings in a RSS feed in a kind of loop so I can write some code at the start and end of it. (But I guess the text I write at the start and end will probably need to be the same each time.)

So what I really need is some javascript to hide all the other li’s except the first, and only display them when the next/previous buttons are clicked. I would prefer to not use jquery as its going to be a mini 1 page app (But will accept if needs must!)

<img src="previous.jpg" onClick="javascript_to_go_to_previous_li">
<ul>
<li id="sameidasrest">Post 1</li>
<li id="sameidasrest">Post 2</li>
<li id="sameidasrest">Post 3</li>
<li id="sameidasrest">Post 4</li>
</ul>
<img src="next.jpg" onClick="javascript_to_go_to_next_li">

Any way of doing that?

  • 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-17T07:55:04+00:00Added an answer on June 17, 2026 at 7:55 am

    First thing first, you should really use an identifier for your <ul> element. Then, you can’t use the same ID for all your <li> elements. Every element has to have its own ID or, even better, you can use a combination of HTML + CSS + JavaScript to reach your goal.

    HTML:
    <ul id="myList" class="collapsed">
      <li>Post 1</li>
      <li>Post 2</li>
      <li>Post 3</li>
      <li>Post 4</li>
    </ul>
    <button id="btnTest">Click Me</button>
    
    CSS:
    ul.collapsed li:first-child {
      display:block;
    }
    
    ul.collapsed li {
      display:none;
    }
    
    JS:
    document.getElementById('btnTest').addEventListener('click', function(){
      var list = document.getElementById('myList'),
          classes = list.className;
      if ( /collapsed/.test( classes ) ) {
        list.className = classes.replace( 'collapsed', '' );
      } else {
        list.className = classes + ' collapsed';
      }
    });
    

    You can test it at http://jsfiddle.net/ragnarokkr/ZafdC/

    In this example I define the list and a button. The button works like a switch. Every time you click it, the list shows and hides the elements. All simply adding and removing a CSS class from the <ul> element.

    Alternatively, you can use some framework such as jQuery, and in this case you can change the JS above in:

    $('#btnTest').on('click', function(){
      $('#myList').toggleClass('collapsed');
    });
    

    The code to test it at http://jsfiddle.net/ragnarokkr/cUYPq/


    This example is to interactively show/hide single list items using HTML+CSS and bare JavaScript:

    HTML:
    <ul id="myList">
      <li class="show">Post 1</li>
      <li class="hide">Post 2</li>
      <li class="hide">Post 3</li>
      <li class="hide">Post 4</li>
    </ul>
    
    <button id="btnShowOne">Show Item</button>
    <button id="btnHideOne">Hide Item</button>
    
    CSS:
    .hide {
      display: none;
    }
    
    .show {
      display: block;
    }
    
    JS:
    function iterateAndToggleClass( elements, classNameFind, classNameReplace, isTopDown ) {
      if ( isTopDown ) {
        for ( var i = 0; i < elements.length; i++ ) {
          var element = elements[i];
          if ( element.className === classNameFind ) {
            element.className = classNameReplace;
            return;
          }
        }
      } else {
        for ( var i = elements.length - 1; i >= 0; i-- ) {
          var element = elements[i];
          if ( element.className === classNameFind ) {
            element.className = classNameReplace;
            return;
          }
        }
      }
    }
    
    document.getElementById('btnShowOne').addEventListener('click', function(evt){
      evt.preventDefault();
      evt.stopPropagation();
    
      var list = document.getElementById('myList'),
          items = list.getElementsByTagName('li');
    
      iterateAndToggleClass( items, 'hide', 'show', true );
    });
    
    document.getElementById('btnHideOne').addEventListener('click', function(evt){
      evt.preventDefault();
      evt.stopPropagation();
    
      var list = document.getElementById('myList'),
          items = list.getElementsByTagName('li');
    
      iterateAndToggleClass( items, 'show', 'hide', false );
    });
    

    Of course this is not optimized code, but I hope it’s clear enough. You can test it at http://jsfiddle.net/ragnarokkr/swGEY/

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

Sidebar

Related Questions

I currently have some JavaScript code that calls a .php file to send me
I have a php page and i have some javascript code to have a
I have a php script that uses some css/javascript tabs, they work on my
I have some javascript code with do while outer loop and switch inner loop,
i have some javascript roll over code that works fine in firefox but when
I have some Javascript code that will programmatically register an COM interop assembly by
I have a table generated from some PHP code that lists a SMALL amount
i need to have some php code inside javascript <script ...> <?php echo ...
I have some javascript/jquery code and need to some php into it be the
I have written some JavaScript code that will read from the Google Maps API

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.