Guide on designing a navigation list with unique buttons that alter the displayed content based on the selected button

As a newcomer to the world of programming, I have a basic inquiry that I hope you can assist me with.

I have successfully created a navigation list, but I am struggling to make it functional. For instance, if my navlist consists of 3 buttons: Home, About, and Contact Me, how do I ensure that clicking on each button changes the content on my webpage accordingly? In other words, how can I display different text or content when a user clicks on the About or Contact Me button?

I apologize for my lack of experience in this matter as a beginner, but any guidance you could offer would be greatly appreciated.

Thank you in advance for your assistance!

Answer №1

In most cases, those "buttons" are actually links that are created using the anchor tag (<a>). The link destination is determined by the href attribute on the tag, which is a URL. This URL can either be absolute (http://example.com) or relative (about.html).

Here's an example of a link:

<a href="about.html">About</a>

When a user clicks on a link, the browser will navigate to the specified page in the href.

I suggest delving into any introductory HTML resources for a more comprehensive understanding.

If you absolutely need to use literal buttons (not stylized links), there are two methods you could employ:

  1. Make the button a submit button and place each one within its own form. The page associated with the button is defined as a URL in the action attribute of the form:

    <form action="about.html" method="GET">
        <input type="submit" value="About">
    </form>
    

    or

    <form action="about.html" method="GET">
        <button>About</button>
    </form>
    

    (Using a <button> tag allows for more customized text on the button. Also, since the default type of a <button> is submit, explicit type="submit" isn't necessary.)

  2. Add an onclick handler to the button. I advise against this for various reasons, including the fact that it won't work if the user doesn't have JavaScript enabled, although that scenario is rare.

    <input type="button" onclick="location = 'about.html'" value="About">
    

    or

    <button type="button" onclick="location = 'about.html'">About</button>
    

Answer №2

Most scenarios will incorporate CSS as well. To display them all in a list format, you can include the following code in your HTML:

<ul class="navmenu">
  <li><a href="index.html">Home</a></li>
  <li><a href="about.html">About</a></li>
  <li><a href="contact-me.html">Contact Me</a></li>
</ul>

Furthermore, your CSS styling would be as follows:

<style>
ul.navmenu {
/* Insert your custom UL MENU CSS styles here*/
}
ul.navmenu li {
/* Insert your custom LIST CSS styles here*/
}
ul.navmenu li a {
/* Insert your custom LINK CSS styles here*/
}
</style>

If you want to modify the appearance of the buttons, you can research "CSS list style" for additional guidance. This should help you get started.

In order to make the buttons change content, you must create pages. For instance, you would need to create index.html (or index.php, or other page formats), about.html, and contact-me.html. These pages are necessary so that your links will navigate from one page to another when clicked.

Answer №3

For those just starting out in the world of web development, my suggestion would be to avoid creating a navbar from scratch. Instead, consider utilizing a framework like Twitter Bootstrap, which offers a pre-built navbar component.

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

Error occurred while retrieving JSON array using Jquery

var groupMembers = $.parseJSON(members); $.each(groupMembers, function (index, item) { $.ajax({ type: "POST", url: "'.base_url(" / panel / listNotifications ").'/'.$id.'/" + valueSelected, d ...

Strategies for sending checkbox data to MySQL via AJAX and jQuery

Looking for assistance on passing values of multiple checkboxes to MySQL using arrays with AJAX (jQuery). I've written two separate code snippets, is there someone who can help me merge them? $(document).ready(function(){ var selected = []; $(&apo ...

HTML Backup Page

Is there a way I can create a fallback page? For example, my method for updating pages on my website involves deleting the original index.php and replacing it with a separate index.html that displays a "We'll be back soon!" message. This is to notify ...

Finding a jQuery DOM element without using a loop

Can the element in variable d be identified directly instead of looping through each function? Take a look at the DOM below: <!DOCTYPE html> <html lang="en"> <head> <title></title> <script src="../jquery-ui ...

Tips for incorporating an if statement within a jQuery each loop

I am having trouble extracting a value from a JSON string based on a certain condition. I have a dropdown menu with two options - 4Seater and 8Seater, and when the user selects one of these options, I want to display all corresponding car names in anothe ...

Error encountered in React: Unable to access property of splice as it is undefined

As I am still getting acquainted with React/JS, I am currently navigating through the process of developing a mobile website. My main goal is to incorporate a delete function without the use of a button. My approach involves utilizing a long-press event, a ...

Below and above the number 10

Struggling with a challenging coding problem, I am completely stumped on how to make it work. function(obj) { if ( (obj < 10) && (obj > 10) ) { return true; } } I've attempted various solutions such as manipulating the varia ...

Colorbox scalePhotos function malfunctioning

The scalePhotos option in Colorbox does not seem to be working correctly for me. I have tried various methods to set it, including initializing Colorbox using the following code snippet right before the closing </body> tag in my HTML: jQuery('a ...

The power of ReactJS and the mysterious nature of 'this'

The code below is currently functioning: fetchPost (id) { var mainObject = {}, toReturn = [], promises = []; var that = this; for(var i=id; i<10; i++) { promises.push(axios.get(`api/posts/${i}`)); } axios.all(promises).then(function(resul ...

What is the best way to toggle the visibility of the answers to a question when the corresponding hyperlink is clicked, and how can the text on this hyperlink be updated dynamically using jQuery?

I am currently working on a website using PHP, Smarty, and jQuery. On this website, I have a page that features a list of questions along with their available answer options and the correct answer. This page is dynamically generated using the "Smarty Tem ...

How can we ensure that an enum is accessible throughout the entire meanjs stack?

Currently, I am exploring the meanjs technology stack and facing a challenge in creating a centralized enum array that can be accessed throughout the project, from MongoDB to Angular. Can anyone suggest a smart solution for accomplishing this task? ...

Display information in a table format by utilizing local storage with jQuery

I have encountered two issues while printing data in my table. When pulling data from localStorage to display in the table, I am facing some challenges. The data is saved correctly in localStorage as per requirements. However, the problems arise during th ...

Is there a way to display a date that is two days before the current date in a React date picker using only vanilla JavaScript

Greetings, I am currently immersed in working with a Shopify app that utilizes React. Unfortunately, I do not have access to their code base or API. The challenge at hand is sending the correct delivery date to the Shopify system. The app currently allows ...

Switch up the text within the URL of the background image

Simply put, this is the structure I have: <div id="RelatedPosts1"> <div class="related-posts-thumb" style="background: url(http://xxxxxxx/s72-c/image-1.jpg)"></div> <div class="related-posts-thumb" style="background: url(http: ...

What is the best way to make an element unclickable on an HTML page while still making it draggable using jQuery's draggable

One way to create an element on a page with a mouse click is by using the following code: $("#sheet").append('<input class="elements" id="Button12" type="button" value="button" />'); If you want the element to be temporarily unclickable, ...

Displaying dynamic data with Vue.js and Chart.js

I am currently working on a VueJS code to display a bar-chart: Vue.component('bar-chart', { extends: VueChartJs.Bar, data: function () { return { datacollection: { labels: ['MICROFINANZAS -SECTOR C ...

Encountering a START_ARRAY token during a spring ajax call

Here is an example of a JSON object: [ { "usernameid": [ "2", "7" ], "phaseid": [ "2", "7" ], "weekstartdate": "2014-11-02" } ] In my controller, I am trying ...

Dealing with a Node and Express server can be tricky, especially when trying to proxy a POST request along with parameters. You might encounter the error

I am trying to forward all requests made to /api/ from my local node server to a remote server, while also adding some authentication parameters to them. Everything works smoothly for GET requests with query parameters and POST requests without specifying ...

What steps can be taken to resolve a Mediasoup installation error in a Node.js environment?

While attempting to install the mediasoup library, I ran into an error that has me stumped. If anyone has encountered this issue before or knows how to solve it, any assistance would be greatly appreciated. > <a href="/cdn-cgi/l/email-protection" c ...

Unlocking the Power of Global Variables in HTML Pages with JTemplate and jQuery

Currently, I am utilizing jtemplate (jquery) and have an htm file structured as follows: <table width="100%" border="0" cellpadding="0" cellspacing="2"> <tr class="dark_color"> <th> Offer </th> & ...