Skip to content
Advertisement

javascript function to selectively show and hide contents by Id

I am working on a project where I want to show page contents selectively.

  1. Have buttons “next” and “previous”
  2. contents are id-ed in a serial manner.

what I want to achieve is at the first page loading, show the first content(id=’item-0′) and only show the “next” button since there is no previous content, and when click on “next” button, hide currently showing contents(id=’item-0′) and show all the contents that are in (id=’item-1′) and so forth, and do not show the “next” button when it’s the last content.

this is what I got so far, on the page I first load every contents with display: none; so, nothing’s showing up of course. but I want to be able to show the first content(id=”item-0″) by changing the style display to inline-block. and then update the “which” that’s in the “next” button onclick action to the next id which is id=”item-1″ and dynamically update this “which” whenever either “next” or “previous” buttons clicked.

JavaScript

So far I worked on:

JavaScript

what I haven’t figured out are:

  1. how to update the current_which and next_which that go in to the “Next” and “Prev” buttons.
  2. how to not show “Prev” button when the page is showing the first content, and how to now show “Next” button when the page is showing the last content.

Advertisement

Answer

I have prepared something for you. If it is not exactly what you are looking for, I hope it’ll you give some general idea on how to achieve what you want.

JavaScript
JavaScript
JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement