The function to clear the vertical tabs div is malfunctioning

I've encountered an issue while learning JavaScript involving a div element. My CV contains four divs that should be hidden, with only the active div visible.

Currently, all the divs are mixed up at the beginning. I want only the general tabcontent to be visible initially...

Any suggestions on how to achieve this?

https://github.com/DevFrancoisXavierPelletier/CV

Answer №1

If you're looking to achieve this in JavaScript, simply insert the following code snippet somewhere in your index.html file:

<script>
    openTab(event, 'General');
</script>

However, it's worth noting that this approach may not be the most efficient. A better and more lightweight method involves utilizing CSS. To do so, add the following CSS class at the bottom of your style.css file:

.tabcontent{
    display: none;
}

.tabcontent:first-child{
    display: block;
}

Answer №2

To style your tabs with CSS, you can simply include the following code:

.tabitem{
    display: none;
}

#Specific {
    display: block;
}

After that, make sure to apply the "active" class to the initial link.

Answer №3

To incorporate the CSS display property:


    #General {
        display: block;
    }
    .tabcontent{
        display: none;
    }
    

Make sure to add the active class to the initial button (General) so that it displays in white when selected:

<button class="tablinks active" onclick="openTab(event, 'General')">General</button>

function openTab(evt, tab) {
    // Define all necessary variables
    var i, tabcontent, tablinks;

    // Hide all elements with class "tabcontent"
    tabcontent = document.getElementsByClassName("tabcontent");
    for (i = 0; i < tabcontent.length; i++) {
        tabcontent[i].style.display = "none";
    }

    // Remove the "active" class from all elements with class "tablinks"
    tablinks = document.getElementsByClassName("tablinks");
    for (i = 0; i < tablinks.length; i++) {
        tablinks[i].className = tablinks[i].className.replace(" active", "");
    }

    // Display the current tab and add an "active" class to the link that triggered it
    document.getElementById(tab).style.display = "block";
    if(evt){
      evt.currentTarget.className += " active";
    }
}
           

html, body {
    margin: 0;
    padding: 0;
    top: 0;
}

#sidebar {
    background: #c5deea;
    /* Other styles */
}

/* Additional CSS Rules */

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

Increment the counter value by one when a new class is created or appended

My goal is to develop a system that increments the 'fault' counter by one every time a wrong answer is submitted. To achieve this, I have configured my system to detect when a class named "incorrectResponse" is generated. However, I am encounteri ...

Converting JavaScript code for Angular: A step-by-step guide

I have been working on integrating a feature similar to the one demonstrated in this Angular project: https://codepen.io/vincentorback/pen/NGXjda While the code compiles without any issues in VS code, I encountered two errors when attempting to preview it ...

When using the jQuery ajax function to validate a form, it is important to note that the $_POST variables

I have an HTML form along with a jQuery function for form validation. After submitting the form values to my PHP files, I notice that the $_POST variable is not being set. What could be causing this issue? <form id="signup" class="dialog-form" action= ...

Using the Google Identity Services JavaScript SDK in conjunction with Vue and TypeScript: A comprehensive guide

I am currently working on authorizing Google APIs using the new Google Identity Services JavaScript SDK in my Vue / Quasar / TypeScript application. Following the guidelines provided here, I have included the Google 3P Authorization JavaScript Library in ...

What is the best method for generating axis helpers with WebGL and Three.js?

Is there a way to create an axis helper similar to the images below, positioned in both the top left corner and center of the scene? Currently, when using axesHelper in Three.js, the lines lack arrows at the end and appear too thin. Here is the code snippe ...

Manipulating the visible area of the image can cause issues in the GWT framework

I'm currently working on a GWT program that displays multiple images on the right side. When hovering over an image, additional information is shown in a custom widget on the left. This info includes a section of the image and a special background tha ...

Vue project encountering issue with displayed image being bound

I am facing an issue with a component that is supposed to display an image: <template> <div> <img :src="image" /> </div> </template> <script> export default { name: 'MyComponent', ...

Could a website potentially generate enough heat to speed up the draining of a Android device's battery?

As I work on a Single Page Application using AngularJS for my website, my client has expressed concerns about users' devices heating up and experiencing faster battery drain when accessing the site. The technologies employed in development include PH ...

Tips on using Ajax to post in HTML

Here is the code I have been working on: <script type="text/javascript"> var xmlDoc; var xmlhttp; function loadRates() { xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = readRates; xmlhttp.open("GE ...

Having difficulty executing the overridden doPost method in a Java servlet

Included below is a snippet of code extracted from a jsp file. <table class="table table-striped table-hover table-responsive ezoo-datatable"> <thead> <tr> <th class="text-center">Schedule ID< ...

How can one ascertain the dimensions of the video margins within an embed-responsive video container?

I am in search of a solution to extract information from within the embed responsive element. When it comes to embed-responsive video elements, they automatically include internal margins on either the x or y axis to maintain the aspect ratio of the video ...

Struggling to successfully validate a user's return value with AJAX

When the user enters incorrect information, I need to ensure that the okLogin variable is set to false and prevent the form from being submitted. However, I have noticed that the return statement in my function is being executed before the ajax call, which ...

It seems that there is a null value being returned in the midst of the

I have developed a model using express. While setting this in one function, it returns null in another function, forcing me to use return. What is the proper method to handle this situation? const Seat = function(seat) { this.seat = seat.seat; this. ...

Utilizing the `find()` method to locate a specific element and also selecting its parent element

I've been experimenting with creating a highlighting effect for some time now. I'm very close to achieving what I want, but the issue with my current method is that it excludes the innermost parent element. What I'm looking for is the same ...

What is the best way to determine if a jQuery AJAX response contains HTML elements?

On my webpage, I have a single form that triggers an AJAX call which can result in two different responses. One of the responses only includes a status code. In order to display any HTML contents returned by the response object on my page, I need to exami ...

The autoplay feature for YouTube videos is not functioning on Chrome when viewed on an iPhone

if($('.explore-video-btn').length > 0) { var video_id = youtube_parser($('.explore-video-btn').attr('data-video-url')); } var tag = document.createElement('script'); tag.src = "https://www.youtube.com/iframe_api" ...

Creating a texture in Three.js using an image file

Having some difficulty with creating a texture from an image file using Three.js. Currently, attempting to create a mesh using the following function: var image = document.createElement('img'); image.src = imageFile; var texture = ne ...

Troubleshooting: Why isn't my Ajax post functioning correctly with PHP variables?

After researching similar questions, I have discovered that in order to send a JavaScript value to a PHP variable, AJAX must be used. Here is what I have tried: function onCursorChanged(e, data) { $.post('familytree.php', {id: data.context.i ...

Struggling to make Datatables function properly with basic JSON data

As a newcomer to frontend development, I'm attempting to convert a JSON call into a table format. After researching, it seems like datatables is the best tool for this task. However, I'm struggling to make it work. Here is my JSON GET call: GET ...

Exploring the possibilities of ASP.NET paired with HTML5 web storage

I am currently working on an application and I have a feeling that utilizing html5 web storage, specifically localstorage, could greatly benefit me. However, the implementation is proving to be more challenging than anticipated. It's possible that my ...