Sorting two different divisions is an example

I need advice on how to toggle between two divs, A and B, without having to reload the page. Ideally, I would like to have three buttons - one that shows only div A when clicked, another that displays only div B, and a third button that shows both A and B.

Answer №1

<div id="X" style="dispay:none">
  <p> this is div X </p>
</div>
<div id="Y" style="dispay:none">
  <p> this is div Y </p>
</div>
<input type="button" value="showX" onclick="showX()">
<input type="button" value="showY" onclick="showY()">
<input type="button" value="showXY" onclick="showXY()">
<script>
  var showX = function()
  {
   document.getElementById('X').style.display = 'block';
   document.getElementById('Y').style.display = 'none'; 
  }
  var showY = function()
  {
   document.getElementById('Y').style.display = 'block';
   document.getElementById('X').style.display = 'none'; 
  }
  var showXY = function()
  {
   document.getElementById('X').style.display = 'block';
   document.getElementById('Y').style.display = 'block'; 
  }
</script>

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

"Adjusting the position of series data container in Highcharts JS to optimize

Currently, I am utilizing highcharts along with highcharts-ng. My goal is to adjust the position of the container for series Data (where the number 80 is displayed below) slightly higher as it is currently overlapping with the numbers 200 and -200 in the t ...

Avoid form submission when the 'enter' key is pressed in Edge, but not in Chrome or Firefox

I'm dealing with an issue in HTML where a 'details' tag is set to open and close when the user presses enter. However, on Edge browser, pressing enter on the 'details' tag actually submits the form. I've been tasked with preve ...

A guide on adding an onClick listener to a span element dynamically and then saving it to MongoDB

I have been attempting to add an onClick event within a span tag as shown below, with the goal of storing it in MongoDb. However, my event does not seem to be saving and is automatically removed. When I retrieve data from the database, it is not present. H ...

sending multiple array values to back-end with c#

How can I pass values from client side to server side in the code behind? ...

Resolving the Smooth Scrolling Problem

Here is a simplified version of what I am currently working on: Although I have managed to get the scrolling functionality to work, there seems to be an issue with transitioning from one section to another. For example, when clicking on NUMBER 3, it s ...

Creating auto serial numbers in the MERN stackWould you like to know how to

I need help coming up with a way to automatically generate serial numbers for my "ticketno" field. Every time a user creates a new application ticket, the ticket number should increment by one. Can someone guide me on how to achieve this? This i ...

Using the active class feature in React Router

Hey there! I've been working with react router v6 and using NavLink to move between components. I've been trying to figure out how to add a custom active class in NavLink, but the method I tried isn't working. Here is what I attempted: <N ...

Using JavaScript with React to invoke an asynchronous action within a component

Within my class, I have implemented some asynchronous actions in the ComponentDidMount method. The code snippet looks like this: componentDidMount(){ // var my_call = new APICall() Promise.resolve(new APICall()).then(console.log(FB)) } class API ...

JavaScript AJAX Event Listener

Currently seeking a way to intercept ajax events in JavaScript before any Ajax method is triggered. While there is an ajaxListener in JQuery that could work if all the ajax requests were from JQuery, unfortunately, they are not. So the question remains: ho ...

Troubleshooting: Issue with Displaying $Http JSON Response in AngularJS View

Struggling to retrieve JSON data from an API and display it in a view using AngularJS. Although I am able to fetch the data correctly, I am facing difficulties in showing it in the view. Whenever I try to access the object's data, I constantly receive ...

What is the best way to retrieve an item using a composite key?

const dynamoDB = new AWS.DynamoDB.DocumentClient(); var parameters: any = {}; parameters.TableName = 'StockDailyCandles'; var primarykey = { 'symbol': 'AAPL', 'datetime': '640590008898' }; // sa ...

managing websocket connections across various instances

Looking to grasp the concept of managing websockets across multiple instances in order for it to be accessible by all instances. For example, with three nodes running connected through a load balancer, data needs to be emitted on a specific socket. My init ...

Importing three.js using ES6 syntax

When it comes to working with ES6, my workflow involves using Babel and babel-plugin-transform-es2015-modules-system.js specifically to transform module import/export for compatibility with system.js. I rely on a "green" browser for most ES6 features excep ...

Is there a way to efficiently use AJAX and PHP to iterate through JSON data and save it to a new JSON file

I have created a simple movie editor with a sidebar where users can drag and drop elements. On the right side, users can edit these elements as they wish and save the data to a JSON file. When the user clicks save, I want it to create a new file and save t ...

Closing tag in jQuery

In my script, I am using a div tag within the jquery code. However, whenever the div tag appears in the jquery code, it automatically closes the script tag and breaks the jquery code. For example, consider the following code: <script>var b = 25;var ...

No matter how hard I try, I can't seem to get any of my jQuery events to function properly on my

Help! I'm encountering issues with jQuery on my webpage. It's not functioning at all, despite my extensive search for a solution. Feeling desperate, I'm reaching out for assistance here. Below are my HTML and JS files: HTML <html> ...

Sending an array and an object simultaneously through a single ajax request

I previously inquired about passing an object to an ajax request for my rest service. Now I am wondering if it's possible to pass both an array and an object within a single ajax request. Any insights on this matter would be greatly valued. ...

What are the differences in how a link tag responds on mobile devices?

I have a question regarding opening a pdf in an iframe on the current page. Is there a way to handle this differently for mobile/tablet users? For example, clicking the link could open it in another tab for better readability instead of within the iframe ...

button that smooth slides out using jquery

Here is the source code for a jQuery slideout: jQuery(function($) { $('#slideClick').toggle(function() { $(this).parent().animate({left:'0px'}, {queue:false, duration: 500}); }, function() { $(t ...

What is the precise location for placing the UpdatePanel control within a form?

I'm a beginner with ASP.NET and I need help figuring out where to place the asp:UpdatePanel control, its contenttemplate, and any necessary triggers in order to validate without triggering a postback. Can anyone offer guidance? <form method="post ...