Tips for updating content within two separate tabs using jQuery

By default, the home tab is displaying blank as per the code below. Content will only appear when the product ordering tab is clicked. I initially implemented this logic in JavaScript, but encountered issues when trying to replicate it in jQuery. Can anyone assist with resolving this?

Additionally, can someone provide guidance on how to mark the selected tab with a different color like Blue when clicked?

function show_menu(elementId) {
  document.getElementById("home").style.display = "none";
  document.getElementById("id2").style.display = "none";
  document.getElementById(elementId).style.display = "block"; }
.wrapper {
  margin: 0px auto 0px auto;
  padding: 3px 0px 0px 0px;
  width: 100%;
}
.container {
  margin: 0px auto 0px auto;
  padding: 0px 0px 0px 0px;
  width: 900px;
  height: 500px;
  background-color: white;
  border: 1px solid green; 
} ... 
<!DOCTYPE>
<html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">

<head profile="http://gmpg.org/xfn/11">
  <title></title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  
  <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.js"></script>
  
</head>

<body>
  <div class="wrapper">
    <div class="container">
      <h2 align="center">Demo</h2>

      <div class="menu_container">
        <div class="menu_font" onclick="show_menu('home');">Home</div>
        
        <div class="menu_font" onclick="show_menu('id2');">Product Ordering</div>
        <div class="clear"></div>
      </div> ... 

Answer №1

$(document).ready(function(){
$('.menu_font').click(function(){
var menutype=$(this).attr('data-menuname');
$('.menu_font').removeClass('active');
$('.pagecontent').hide();
$('.'+menutype).show();
$(this).addClass('active');
});
$('.leftmenu').click(function(){
var menutype=$(this).attr('data-leftmenuname');
$('.leftmenu').removeClass('active');
$('.middle_container_right').hide();
$('#'+menutype).show();
$(this).addClass('active');
});
});
.wrapper {
    margin: 0px auto 0px auto;
    padding: 3px 0px 0px 0px; 
    width: 100%;  
}
.container{
    margin: 0px auto 0px auto;
    padding: 0px 0px 0px 0px; 
    width: 900px;  
    height: 500px;
    background-color: white;
    border: 1px solid green;
}
.clear{
    clear: both;
}
.menu_container{    
    margin: 0px;
    padding: 0px;
    width: 900px;
}
.middle_container{
    margin:0px;
    padding:0px;
    width: 900px;
}
.middle_container_left{
    margin:0px;
    padding:0px;
    width: 300px;
    height: 246px;
    border-right: 1px solid black;
    border-bottom: 1px solid black;
    border-top: 1px solid black;
    float:left;
}
.middle_container_right{
    margin:0px 0px 0px 10px;
    padding:0px;
    width: 580px;
    height: 300px;
    /*border: 1px solid black;*/
    float:left;
}
.menu_font{
    margin: 0px 5px 0px 0px;
    width: 100px;
    height:30px;
    float:left;cursor:hand;
    text-align:center;
    padding-top:5px;
    font-weight:bold;
    background-color: #8eaf64;
    border-radius:5px 5px 0 0;  
    color: white;
}
.menu_font:hover{
    margin: 0px 5px 0px 0px;
    width: 100px;
    height:30px;
    float:left;cursor:hand;
    text-align:center;
    padding-top:5px;
    font-weight:bold;   
    color: white;
    background-color:#64A70B !important;
    border-radius:5px 5px 0 0;
}

.onoffswitch {
    position: relative; width: 63px;
    -webkit-user-select:none; -moz-user-select:none; -ms-user-select: none;
}
.onoffswitch-checkbox {
    display: none;
}
.onoffswitch-label {
    display: block; overflow: hidden; cursor: pointer;
    border: 2px solid #999999; border-radius: 20px;
}
.onoffswitch-inner {
    display: block; width: 200%; margin-left: -100%;
    transition: margin 0.3s ease-in 0s;
}
.onoffswitch-inner:before, .onoffswitch-inner:after {
    display: block; float: left; width: 50%; height: 30px; padding: 0; line-height: 30px;
    font-size: 14px; color: white; font-family: Trebuchet, Arial, sans-serif; font-weight: bold;
    box-sizing: border-box;
}
.onoffswitch-inner:before {
    content: "ON";
    padding-left: 6px;
    background-color: #85a857; color: #FFFFFF;
}
.onoffswitch-inner:after {
    content: "OFF";
    padding-right: 2px;
    background-color: #EEEEEE; color: #999999;
    text-align: right;
}
.onoffswitch-switch {
    display: block;
    width: 30px;
    margin: 6px;
    background: #FFFFFF;
    position: absolute;
    top: ...
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<div class="wrapper">
    <div class="container">
        ...
    </div>
</div>

Answer №2

To accomplish this task, you can make use of the jQuery method show/hide.

Below is the revised code snippet:

$(document).ready(function(){
    $('.menu_font_home').click(function(){
        $('#id2').hide();
        $('#home').show();
    })
 
    $('.menu_font_product_ordering').click(function(){
        $('#quick_add,#solution_builder,#bulk_load,#product_search,#saved_cart,#view_favorites').hide();
        $('#id2').show();
    })   
});
.wrapper {
  margin: 0px auto 0px auto;
  padding: 3px 0px 0px 0px;
  width: 100%;
}

.container {
  margin: 0px auto 0px auto;
  padding: 0px 0px 0px 0px;
  width: 900px;
  height: 500px;
  background-color: white;
  border: 1px solid green;
}

.clear {
  clear: both;
}

.menu_container {
  margin: 0px;
  padding: 0px;
  width: 900px;
}
/* Additional CSS code omitted for brevity */</answer2>
<exanswer2><div class="answer" i="42407387" l="3.0" c="1487815155" v="1" a="U3VwZXIgVXNlcg==" ai="3756181">
<p>You can implement the show/hide functionality using jQuery.</p>

<p><strong>Here is the updated code:</strong></p>

<p><div>
<div>
<pre class="lang-js"><code>$(document).ready(function(){
    $('.menu_font_home').click(function(){
        $('#id2').hide();
        $('#home').show();
    })
 
    $('.menu_font_product_ordering').click(function(){
        $('#quick_add,#solution_builder,#bulk_load,#product_search,#saved_cart,#view_favorites').hide();
        $('#id2').show();
    })   
});
.wrapper {
  margin: 0px auto 0px auto;
  padding: 3px 0px 0px 0px;
  width: 100%;
}

.container {
  margin: 0px auto 0px auto;
  padding: 0px 0px 0px 0px;
  width: 900px;
  height: 500px;
  background-color: white;
  border: 1px solid green;
}

.clear {
  clear: both;
}

.menu_container {
  margin: 0px;
  padding: 0px;
  width: 900px;
}

.middle_container {
 // Add your styles here
}

// ... Remaining CSS and HTML code truncated to maintain brevity

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 is the reason behind Drupal 8 appending a GET variable to the end of each CSS file and resulting in a 404 error?

I've been struggling for hours trying to figure out why the CSS is not loading on the Drupal 8 site I'm migrating. Despite successfully resolving other issues, the CSS files are throwing a 404 error, specifically due to a GET variable (?oe62rp) a ...

Displaying data retrieved from Angular by clicking a dropdown button

Struggling with a minor issue while using Angular on the frontend and .NET Core on the backend? Look no further, I have created a video demonstration below to help you out. Despite spending countless hours trying to solve the problem, it still persists. T ...

Having trouble with the cookie functionality in Ionic Angular JS?

app.js angular.module('starter', ['ionic', 'starter.controllers', 'starter.services', 'ngCordova', 'ngCookies']) .run(function ($ionicPlatform) { $ionicPlatform.ready(function () { if (window.c ...

The TSX file is encountering difficulty rendering an imported React Component

Upon attempting to import the Day component into the Week component (both .tsx files), an error is thrown: Uncaught Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object. ...

Utilizing jQuery to Load a Compressed Script File

I am attempting to load and run a gzipped script! The script load.js: $(document).ready(function() { $("#ls_text").text("loaded!"); }); Compressed with 7zip as load.js.gz. This is my node.js express code for serving the file: app.get('/load.js ...

Creating an object from select options in buildSelect methodWant to know how to convert

Based on the information from the http://www.trirand.com/jqgridwiki/doku.php?id=wiki:search_config, the value property can be defined as an object: If set as an object, it should be defined as a pair value:name - editoptions:{value:{1:'One',2:&a ...

"Chrome supports inline JavaScript functionality, while Firefox does not seem to handle it effectively

I'm having an issue with my page layout where I've set up an HTML table structure. I want to display static text if the td is empty. Here's the code I'm using: <td> <div id="dvCountry"> <SharePointWebContro ...

What is causing this code to keep iterating endlessly?

I have a basic jquery script embedded in my HTML code that utilizes the cycle plugin for jQuery. The problem I'm facing is that when I interact with the slideshow using the "next" or "previous" buttons, it continues to loop automatically after that in ...

Tips on preventing form submission when clicking on another button within the same form

I created a shopping cart page with functionality to adjust the quantity using JavaScript. I have shared some of the HTML code below, <form action="payment.php" method="post"> <div class="qty__amount"> ...

Does HTML store information in Access databases?

Currently facing an issue, but first let's take a look at what resources I have. Current Resources: • A DB File in ACCESS containing over 100 lines of data. • An HTML webpage with inputs corresponding to the fields in the ACCESS file. • My o ...

What is the most efficient method for executing multiple variable=function() and determining when all tasks have been finished?

I am facing the issue of having multiple variables that need to be calculated before being saved as a JSON file. These calculations are done using a function, but when run asynchronously, they end up undefined. After reading about promises, it seems like t ...

Easily resolving conflicts by removing `package-lock.json`

Whenever I work in a team environment, I often encounter merge conflicts with the package-lock.json file. My usual solution is to simply delete the file and generate it again using npm install. So far, I haven't noticed any negative effects from this ...

Animated mosaic pattern menu design

Is there a way to achieve this effect with a sketch? Note: I would like to add hover animation to the borders if possible. I attempted to do it using the following code: clip-path: polygon(0 0, 100% 0, 92% 86%, 6% 100%); However, the shapes created by ...

Incorporate a personalized JavaScript code segment during the Vue build process

I am currently working with Vue CLI and I need to include a custom javascript section in the default template when I release my project. However, I do not want this section to be included during the debugging phase. For example, I would like to add the fo ...

Utilizing Vue.js with XML data streams

I ran into a problem while working on my personal site with Vue.js. My goal is to display the five latest posts from my Jekyll blog on the page. To achieve this, I am checking the feed at http://todayilearned.dk/feed.xml. However, I'm struggling to ...

What is the best way to individually target buttons using jQuery?

Is there a more efficient way to create a dropdown effect on three paragraphs on the same line without breaking the "DRY" rule of programming? Below is the current solution I have implemented, but it feels like there might be a faster approach. $(funct ...

Implementing a translucent overlay onto a specific HTML section using sidebar.js/jQuery

Searching for a way to enhance the functionality of my website using Sidebar.js, I came across an interesting feature on hypebeast.com. When you click on the three-bar icon, the main container section's opacity changes. How can I achieve this effect? ...

I was surprised by how Await behaved in if-else statements, it was not what

let metadata = []; allNFTs.map(async (e) => { if (e.metadata) { metadata.push(JSON.parse(e.metadata).attributes); } else { let config = { method: "get", url: `http://localhost:3000/api/fetch ...

End the div element upon completion of the Vimeo video

I am in need of a website that includes an intro video displayed as a full-width div over the background content. To achieve this, I created a Div containing an iframe video from Vimeo along with a button to skip the intro (which closes the div upon clicki ...

Dynamically retrieve search options in Flexigrid using jQuery

Currently utilizing flexigrid, I have managed to retrieve all selected rows using the following query: find("tr.trSelected") Now, I am attempting to obtain the current search options using similar methods but unfortunately not getting any value. I have a ...