How can I input text into separate tabs using a specific method?

I've been struggling with this issue for a while now and here's the code I have so far:

<html>
    <head>
        <script src="http://mihaifrentiu.com/wp-content/themes/mf/js/jquery_1.7.1.min.js" type="text/javascript"></script>
        <style type="text/css">
            body, html, div, ul, li, a {
                margin:0;
                padding:0;
            }
            body {
                font-family:arial;
                font-size:12px;
                color:#000000;

            }
            .clear {
                clear:both;
            }
            ul {
                list-style:none;
                position:relative;
                z-index:2;
                top:1px;
                display:table;
                border-left:5px solid #808080;
            }
            ul li {
                float:left;
            }
            ul li a {
                background:#000000;
                color:#000000;
                display:block;
                padding:6px 15px;
                text-decoration:none;
                border-right:100px solid #000000;
                border-top:1px solid #000000;
                border-right:3px solid #808080;
            }
            ul li a.selected {
                border-bottom:1px solid #808080;
                color:#000000;
                background:#808080;
            }
            h1 {
                display:block;
                width:600px;
                margin:0 auto;
                padding:200px 0;
                color:#000000;
            }
            #navigation {
                width:602px;
                margin: 0 auto;
            }
            #content {
                width:600px;
                margin:0 auto;
                height:200px;
                background:#ffffff;
                border:1px solid #000000;
                z-index:1;
                text-align:center;
                padding:10px 0;
            }
            #logo {
                width:600px;
                margin:0 auto;
                padding:10px 0;
                text-align:right;
            }
        </style>
    </head>

    <body>
        <div id="navigation">
            <ul>
                <li><a href="javascript:void(1);" id="tab1"><font color="white">Tab 1</a></li>
                <li><a href="javascript:void(2);" id="tab2"><font color="white">Tab 2</a></li>
                <li><a href="javascript:void(3);" id="tab3"><font color="white">Tab 3</a></li>
                <li><a href="javascript:void(4);" id="tab4"><font color="white">Tab 4</a></li>
                <li><a href="javascript:void(5);" id="tab5"><font color="white">Tab 5</a></li>
            </ul>
            <div class="clear"></div>
        </div>
       <div id="content">
            <p id="content_changer">You've chosen Tab 1</p>
            <p>Check the page source for full code</p>
        </div>
        <script type="text/javascript">
            $(document).ready(function() {
                $('#navigation ul a').click(function() {
                    $('#navigation ul a').removeClass('selected');
                    $(this).addClass('selected');
                    $('#content_changer').html('You've selected ' + $(this).html());
                });
            });
        </script>
    </body>
</html>

I'm having trouble getting one of these tab menu things to work, I've tried numerous methods but nothing seems to be working.

Answer №1

Although it may not be the most efficient code, it gets the job done for my needs. The main issue lies in the fact that the text within the #content element is styled with a white font color, making it invisible despite being present.

It's advisable to steer clear of using font tags as they are outdated, and also refrain from incorporating inline JavaScript for better coding practices.

Answer №2

After testing your script, I noticed that the text is displayed within the #content_changer element, but it appears white in color. To resolve this issue, you can implement the following CSS rule:

#content_changer{
    color:#000;
}

Additionally, modify $(this).html() to $(this).text(). This adjustment should resolve the problem.

Answer №3

The issue lies not within your JavaScript code, but rather in the CSS styling. The font color is set to white for the links in the navigation bar, making them invisible against the background of the content area. It is also worth noting that using is now considered deprecated, and you should update the content-area color to black.

For reference, you can view a functional example on jsFiddle: http://jsfiddle.net/8ftyy/

The key differences between your original code and the corrected version are as follows:

#content_changer {
color: black;
}
ul li a {
color: white;
}

Additionally, avoid specifying font colors directly in the HTML markup.

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

What are the ways to utilize vue-i18n setup within and beyond Vue components when working with Quasar?

Hello, fellow developers. I am currently working on implementing internationalization in Quasar, using Vue 3 (Composition API) and vue-i18n. My goal is to make internationalization available throughout the entire application, not just within Vue components ...

Utilize JavaScript, MySQL, and PHP to input data into a database

My JS function is supposed to make an ajax request, but for some reason it's not working. I've checked the URL in an alert and all variables are declared. var request = new XMLHttpRequest(); var url = "ajax_js/q_ajax.php?q="+ques+ ...

The alignment of Div elements is off in IE8

I have been struggling to align two divs side by side without any empty spaces on IE 8. Everything looks perfect on Chrome Version 35.0.1916.153 m and Firefox 30.0, but IE 8 seems to be causing some issues. All I want is a main div with two child divs ali ...

What is the best way to pick out specific passages of text

I'm attempting to create an autocomplete feature where the data is displayed in a div below the text box as the user types. While this typically involves ajax, I've simplified the approach without using jQuery autocomplete. Once the text appears ...

Looping through color transitions upon hover using CSS

I am trying to create a color transition effect on hover, where the background changes from yellow to red and then back to yellow in a loop. I'm having trouble figuring out how to make this transition repeat continuously. Do I need to incorporate Java ...

Unusual dark streak beneath the Wordpress emblem

I recently created my website using Wordpress and decided to use a PNG image (140*82 px) as the logo instead of the default "site-title". However, I encountered an unusual issue where a black line appeared just below the image. After checking my "header.ph ...

What causes addEventListener to not return a value?

In this snippet of code: let rockClick = rockBtn.addEventListener('click', playRound.bind("rock", computerPlay(), false)); After using console.log(), the output is undefined. The purpose of rockBtn:const rockBtn = document.querySelecto ...

Use JavaScript to enclose elements that are siblings within a DIV

Can you help me convert the elements with class "a" into a div using JavaScript, while maintaining their order within their sibling elements? I've been struggling with the code below and would appreciate any assistance. const elementParent= documen ...

Effectively monitoring coordinates on both the client and server sides

I'm currently in the process of developing a multiplayer game using websockets, node, and JavaScript. I need advice on the most effective approach to update client information and manage their coordinates on the server. The method I am using at the mo ...

Best practices for transferring data in node.js (unresolved)

Is it possible to pipe a file from an external server through localhost using Node.JS? (Imagine loading localhost as if it were another site like ) Here is the scenario: A PC requests http://localhost:80/highres/switch.html The Node application then ...

What is the solution for resolving the problem of the cursor jumping to the end when converting numbers in JavaScript?

After exploring the inquiries regarding converting digits in JavaScript, such as What's the solution and the right way to convert digits in JavaScript? and How to convert numbers in JavaScript, and problems with commands to remove non-numeric characte ...

How can you implement a resource response approach in Express.js using an API?

As a newcomer in my journey with expressjs, I'm currently exploring its functionalities. In my controller, I've structured the response as follows: .... res.json({ 'data': { 'user': { 'id': us ...

Ways to display title attributes when focused using jQuery?

Typically, title attributes in all browsers only appear when the mouse hovers over them. I am looking to also display them when users are focused on them via keyboard navigation. Unfortunately, without using JavaScript, this cannot be achieved solely throu ...

Parsing an Object in Java

I have a JavaScript object that I am sending back to Java using AJAX: var jsonData = { "testJson" : "abc", "userId" : "123" }; After printing the map, it appears as follows: key: jsondata value:[object Object] What is the correct ...

Drop your friend a line, I'm curious about the Javascript API

As a developer hailing from the Republic of Korea, I am currently in the process of creating websites that are based on Facebook and Twitter. I am interested in utilizing a JavaScript API that allows me to send messages to friends. Initially, I considered ...

Struggling to create a mobile-friendly design

I've successfully created a dynamic world map using D3.js, but I need some guidance on making it responsive across various screen sizes. You can view the interactive world map here. Credentials to access the map: Username: DXLdemo Password: ...

show a notification once the maximum number of checkboxes has been selected

I came across this code snippet from a previous question and I'm interested in making some modifications to it so that a message can be displayed after the limit is reached. Would adding a slideToggle to the .checkboxmsg within the function be the mos ...

Obtaining Data from Fetch Response Instance

Currently, I am utilizing the fetch method to execute API requests. While everything is functioning as expected, I have encountered a challenge with one specific API call due to the fact that it returns a string instead of an object. Normally, the API pro ...

Issue with AngularJS directives - encountering a problem with the property 'compile' being undefined

Just starting out with AngularJS and attempting to make a basic directive. Unfortunately, the code is throwing a TypeError: Cannot read property 'compile' of undefined. Any advice or suggestions would be greatly welcomed. JS var xx = angular.mo ...

What is the best way to center align an element while having another element situated directly below it?

I want to create a grid of "clock" elements, with five clocks in each row. Below each clock, I'd like to display the DAY and DATE centered with the clock (day on top line, date below). Since I'm new to html/css, I appreciate your patience. Here&a ...