What is the proper way to display the initial content of the menu?

I am currently working on a website design for an upcoming festival. The festival spans over three days, so I have created buttons to navigate and load the content for each day separately.

Is there a way for me to make the content for the first day display automatically when the website is loaded?

Also, how can I modify the design of the buttons to indicate to users that the content has been successfully loaded?

 <script type="text/javascript">
    $(document).ready(function () {
        $('.btn a').on('click', function(){
            var btnindex = $(this).index();
            $('.pgf .pgfone').siblings('.pgfone').css({'display':'none'});
            $('.pgf .pgfone').eq(btnindex).css({'display':'block'}); 
        });
    });
    </script>

<div class="btn" id="menu">
        <a class="learn-more">DAY 1</a>
        <a class="learn-more">DAY 2</a>
        <a class="learn-more">DAY 3</a>
        </div>
    
    <div class="pgf">
    
            <div class="pgfone" style="display: none;"><?php include('dayone.php'); ?></div>
            <div class="pgfone" style="display: none;"><?php include('daytwo.php'); ?>  </div>
            <div class="pgfone" style="display: none;"><?php include('daythree.php'); ?></div>

    </div>

Answer №1

If you want to achieve this, try removing one of your styles

<div class="pgfone"><?php include('dayone.php'); ?></div>
<div class="pgfone" style="display: none;"><?php include('daytwo.php'); ?></div>
<div class="pgfone" style="display: none;"><?php include('daythree.php'); ?></div>

(P.S:) In relation to the above, I recommend avoiding inline styles and using CSS instead:

/* START BY REMOVING INLINE STYLES AND ADD THIS TO YOUR CSS: */

.pgfone + .pgfone{ display:none; } /* hide all except the first one */

You could also accomplish this with jQuery:

$(".pgfone").eq(0).show();

Check out this demo featuring the necessary button styling:

$(document).ready(function () {
  
  var $learnBtns = $('.learn-more');
  
  $learnBtns.on('click', function() {
    var btnindex = $(this).index();
    $learnBtns.removeClass("active").eq(btnindex).addClass("active");
    $('.pgfone').hide().eq(btnindex).show();
  });
  
});
.pgfone + .pgfone{ display: none; }
.active{background:red;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="btn" id="menu">
  <a class="learn-more active">DAY 1</a>
  <a class="learn-more">DAY 2</a>
  <a class="learn-more">DAY 3</a>
</div>

<div class="pgf">
  <div class="pgfone">ONE</div>
  <div class="pgfone">TWO</div>
  <div class="pgfone">THREE</div>
</div>

Answer №2

Upon reviewing your website, I have come up with a solution for you.

To begin, add the following CSS rule to your page:

a.learn-more.inactive{
    background-color: gray;
    color: black;
    pointer-events:none;
}

In your HTML, make sure to use the data attribute to store the dates when these buttons should be active. Initially, set all buttons to inactive:

<div class="btn" id="menu">
    <a class="learn-more inactive" data-Date="3">DAY 1</a>
    <a class="learn-more inactive" data-Date="4">DAY 2</a>
    <a class="learn-more inactive" data-Date="5">DAY 3</a>
</div>

Then, utilize jQuery to determine the current day and toggle the active state of the buttons accordingly:

 var date = new Date();
 var currentDay = date.getDay(); 

 $('a.learn-more[data-Date="'+currentDay +'"]').removeClass('inactive');

This solution is dynamic, meaning you won't need to manually adjust the code each day to toggle your buttons. The script will automatically determine the current date and activate the appropriate button
. This way, you can focus on enjoying the festival instead of constantly tweaking the code :)

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

Creating a duplicate of a Flex object in HTML without the need to reinitialize

I'm currently developing a flash object that involves processing a large number of images. My goal is to load multiple flash objects on the same page in order to capture an image, make adjustments, and then display it within each flash object. Howeve ...

Utilizing the power of JSF ajax with Bootstrap's data-toggle feature for radio buttons

Despite my efforts, I have not been able to find a definitive answer on SO. If this question has already been addressed, please point me in the right direction. This is what I currently have: (HTML) <span class="btn-group" data-toggle="buttons-radio" ...

How can strings of dates be arranged in MM/DD/YYYY order?

Is there a correct way to sort these dates in descending order? I've attempted using arr.sort() and arr.sort().reverse(), searched extensively on stack overflow, but still cannot find a solution. Every attempt at sorting them seems to be incorrect. [ ...

The Angular route functions flawlessly in the development environment, but encounters issues when deployed to

I have a project built with Angular 2, During development on localhost, everything runs smoothly. However, once I build a production version using (npm run build: prod) and navigate to the route on the server, I encounter a 404 error indicating that the r ...

How can I display a button (hyperlink) on a new line using CSS or jQuery?

I am looking to create a new line after the last input of my form. On this new line, I want to add a "remove-link". This is my HTML: <div class="subform dynamic-form"> <label for="id_delivery_set-0-price"> Price: </label> <inp ...

Is it possible to select options in AngularJS based on certain criteria?

I created an AngularJS select menu that is currently functioning correctly: <select name="s1" id="s1" multiple="multiple" data-native-menu="false" data-role="none" ng-model="userlistSelect" ng-options="u.userId as u.fi ...

Enhancing React Native experience by dynamically editing array elements

This code block defines the state of my program, including an array: this.state = { arr: [{ arrid: 0, arrEmail: '', arrName: '', arrPhone: '' }], id: 0, email: "", isChecked: true, name: "", phon ...

Placing an item inside the container without exceeding its vertical limit

Check out this jsfiddle - http://jsfiddle.net/az47U/3/ - where you'll find a Gallery div along with a Canvas div, both located within the body. These divs have been absolutely positioned to not affect the overall body height. I've set the body he ...

Sending data using formData across multiple levels of a model in Angular

I have a model that I need to fill with data and send it to the server : export interface AddAlbumeModel { name: string; gener: string; signer: string; albumeProfile:any; albumPoster:any; tracks:TrackMode ...

What is the best way to ensure that my grid remains contained within its designated area?

I need to incorporate a grid of 16x16 or 64x64 into my layout without it overflowing. I'm considering using flexbox, but unsure of the implementation process. My goal is to have the grid resize based on the container size rather than exceeding its bou ...

The animation in an AngularJS directive only functions properly when utilizing $timeout

I can't seem to figure out why the animation is not working as intended in the code below: app.directive('openMenu', ['$animate', '$timeout', function($animate, $timeout) { return { link: function(scope, elem ...

Exploring the differences between JavaScript destructuring and assignment

In my code, I initially used this line: const availableDays = status.availableDays; However, a suggestion was made to replace it with this line: const { availableDays } = status; Both options achieve the same result in one line of code, but I am curious ...

interactive vuetify navigation trail elements

Currently working on a vuetify project and I'm facing an issue with implementing breadcrumbs. The problem arises when clicking on a breadcrumb, as it deletes the ones that come after it in the list. I've tried some code snippets but could only ma ...

Basic HTML Audio Player Featuring Several Customizable Variables

I have a unique API that manages music playback. Instead of playing audio in the browser, it is done through a Discord bot. Achievement Goal https://i.stack.imgur.com/w3WUJ.png Parameters: current: indicates the current position of the track (e.g. 2:3 ...

Effective methods for importing components in VueJS 2.0

As a newcomer to VueJs, I have a question regarding the best practice for importing components in a Vue Template Project. I currently have some components that are used in multiple views. After downloading an admin template, I noticed that the samples alwa ...

A guide on utilizing the javascript function to toggle the checkbox in each row of a gridview

I am looking to implement a function that checks checkboxes row by row based on specific conditions. The first condition requires an alert popup if three checkboxes are selected in the same row consecutively ("You can't select continuous three hou ...

Is it possible to use a Jasmine spy on a fresh instance?

In need of assistance with testing a TypeScript method (eventually testing the actual JavaScript) that I'm having trouble with. The method is quite straightforward: private static myMethod(foo: IFoo): void { let anInterestingThing = new Interesti ...

Steps for incorporating events on Jquery UI button

I have a question about utilizing Jquery UI for the first time. After successfully adding a button using Jquery UI, I am now interested in adding events for when a radio switch is turned on and off. When the radiobox is switched on, I want an alert window ...

Tips for making a circle and a bar overlap using CSS

Trying to create a circular image and a horizontal bar of equal height next to it in a user profile. It needs to be responsive and look like the image below, with text in the black bar. Looking for help with CSS to achieve this: I currently have the cod ...

Dealing with jQuery's scrollTop viewport problem: Adding a personalized value to position().top

I'm currently working on a single-page WordPress site. Since it's all contained on one page, I've implemented jQuery scrollTop to animate the menu when clicked. However, I am facing an issue where the fixed menu is overlapping the content of ...