Revealing text with a single click

Currently, I am enrolled in a beginner HTML/CSS/JS course where our initial task is to create a personal website. The requirement is to incorporate a horizontal menu that reveals specific information when clicked. For instance, selecting "description" should unveil a brief paragraph detailing about ourselves. After conducting some research, it appears that JQuery might be the solution, however, it seems premature for us to know or use it at this stage. Is there an alternative approach that I'm missing?

<html>

<head>
    <meta charset="utf-8" />

    <link rel="stylesheet" type="text/css" href="style.css">
<title>Jeremy Ortiz</title>
<div id="header">
<h1>A Little About Jeremy Ortiz</h1>
</div>

</head>

<body>
    <img src="hwpic.jpg" alt="Me">

    <div id="content">
    <div id="nav">
     <h2>Navigation</h2>
     <ul>
      <li><a class="selected" href="">Description</a></li>
      <li><a href="">A form</a></li>
      <li><a href="">Course List</a></li>
      <li><a href="">Table</a></li>
      <li><a href="">Contact Information</a></li>
     </ul>
    </div>
</body>
</html>



#header {
    padding: 10px;
    background-color: #6CF;
    color: white;
    text-align: center;
}

img {
    position: absolute;
    right: 7px;
    bottom: 148px;
    z-index: -1;
}

#content {
    padding: 10px;
}

#nav {
    width: 180px;
    float: left;
}

table, th, td {
    border: 1px solid black;
    border-collapse: collapse;
}

Answer №1

To achieve this task using basic Javascript instead of navigating the user with <a> elements, I will guide you through a simple and easily readable solution.

Firstly, we can convert your <a> elements to button elements and assign an 'onclick' property to trigger a function when clicked:

<button onclick="displayDescription()">Click Me</button>

Create hidden <div> containers for each button's content that will be displayed upon clicking:

<div id="description" style="display: none;">
  Displayed when the description button is clicked.
</div>

Remember to have a separate hidden <div> container for each button to display the corresponding information.

Next, define the Javascript function to toggle the visibility of the content when the button is clicked:

function displayDescription() {
    var x = document.getElementById('description');
    if (x.style.display === 'none') {
        x.style.display = 'block';
    } else {
        x.style.display = 'none';
    }
}

This approach ensures each button corresponds to specific content, maintaining clarity in the interaction.

If you require further assistance, consider exploring resources like w3schools. Here is a link specifically addressing functionality similar to your assignment: http://www.w3schools.com/howto/howto_js_toggle_hide_show.asp

I trust this explanation proves beneficial; I may refine this response with more details later on. Enjoy learning!

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

Issue with AngularJS Directive: Encountering an error stating "Unexpected token"

Currently working with version 1.20 rc2 and attempting to incorporate a directive: var directives = angular.module('directives', ['controllers']); directives.directive("drink", function() { return { template: '<div>{{f ...

The issue arises when using multiple route files in Route.js, as it hinders the ability to incorporate additional functions within the

After breaking down Route.js into multiple controllers, I'm stuck on why I can't add an extra function to block permissions for viewing the page. // route.js module.exports = function(app, passport) { app.use('/profile&apos ...

Upgrading from Sequelize V5 to V6: TypeScript bug - Property 'x' is not recognized in type 'y'

Updating from sequelize 5.x.x to 6.x.x has caused some issues for me. In version 5, everything was working fine but after the upgrade, I started facing TypeScript errors with properties generated via associations when trying to use objects from the include ...

The footer is not displaying the background image properly

Currently in the process of creating my website. I've successfully added my banner and footer, but unfortunately, I'm facing an issue with the background. It seems to not be stretching out properly, leaving some empty white space. Click here to ...

Is there a way for me to utilize the Bootstrap carousel without it adjusting the height as the user transitions from slide 1 to slide 2?

body{ background-color: #CAF7E3; } .container-fluid{ padding: 3% 15%; } .navbar{ font-family: 'Montserrat'; font-weight: bold; } .navbar-brand{ font-size: 2.5rem; } .nav-item{ margin-right: 2rem; } #title{ padding: 8% 15%; backgr ...

Expanding the jQuery vertical tab content section to span the entire width of the page

I set up a vertical tab interface following the instructions here, but I'm having trouble with the content area not extending all the way across the page. I've been experimenting with adjusting the CSS by adding width='100%' attributes ...

What is the best way to prevent text-decoration from being applied to icons when utilizing font-awesome inside a hyperlink?

I recently began using FontAwesome and it's been going well. However, I have a question about using it with an anchor tag that has text-decoration:none, and on hover text-decoration:underline. Whenever I hover over the link, the icon also receives the ...

Tips for animating slider elements that are not set to absolute positioning

I'm currently working on implementing an animated slider for my website. I have been using floats and margins to position the elements of the slider, but now I want to find a way to incorporate animations without having to use CSS3 transitions with ab ...

Creating a VSCode extension using Vue: Step-by-step guide

I'm looking to develop a VSCode extension with Vue utilizing the VSCode webview. However, when attempting to import the compiled index.html into my extension, I consistently receive a prompt to enable JavaScript. Is there a solution for integrating Vu ...

Retrieve the database value for the chosen name and then add that name to a different table

I am working on a dropdown feature that fetches categories from a database and displays the selected category price in a textfield. For example, when 'web development' is selected, the price ($12) will display in the textfield. Below is the cod ...

CSS filling a height percentage from the bottom up to the top

I have a container div containing a transparent image with only a border. Here is an example: In the "dislike" case, I am able to dynamically change the container's height percentage so it appears as if the figure is being filled. As the height grows ...

Designing custom gridviews using CSS in an ASP.NET application with Bootstrap

Hey there, I'm currently working on a post system using GRIDVIEW in ASP.NET/BOOTSTRAP. Since GRIDVIEW is basically a table, I am using templatefild and itemtemplate with table td and tr to make it resemble a BLOG! Everything is going well so far, I ha ...

Scripting issues detected in Safari and Microsoft Edge browsers

I recently finished developing an AngularJs Application that works flawlessly on Google Chrome and Mozilla Firefox. However, upon testing it on Safari and IE-11, I encountered errors in the console. One particular piece of code that causes issues is used ...

Utilize JQuery to create expand and collapse functionality for a div

Trying to decipher the intricacies of this JQuery code has been quite the challenge for me. I would normally opt for a different approach, but it seems I must adhere to this particular method. My main issue lies in getting the functionality right - when cl ...

Can you explain the function of "app.router" in the context of Express.js?

When looking at the default app.js file generated by express.js, I came across the following line: ... app.use(app.router); ... This particular line of code has left me perplexed for a couple of reasons. First, upon consulting the express api documentati ...

In PHP, validating a value stored in a database against one entered in a text box

My form consists of multiple text fields, with the number determined by the amount of data in a database. Both inputs are integers. I would like to set up a validation where an error is triggered if the inputted value exceeds the corresponding value in t ...

Monitor the links that have been clicked using JavaScript cookies

I have a website with three pages in total. On the first page, there is a button that leads users to the second page when clicked. At the second page, users are given the option to add an 'addon' to their order or skip it. After making their ch ...

Finding image input loading

When working with the following code: <input type="image" ... onLoad="this.style.opacity = 1" /> Everything seemed to be functioning well in IE, but encountered an issue in Chrome where the onLoad event failed to trigger upon image load. It's ...

How to implement CSS styling for a disabled component

In my application, I have a FormControlLabel and Switch component. When the Switch is disabled, the label in FormControlLabel and the button in Switch turn gray. However, I want to maintain the color of both the label (black) and the button (red). To test ...

Show an HTML email message on a webpage without disrupting the existing page layout

Looking for a solution to display mail messages on a web page originating from an exchange server with various style elements that might interfere with the existing page layout. Attempting to load these mail messages within a div results in the style elem ...