Tips for managing div visibility exclusively through the click of a specific div element

I have 4 div containers, each containing an image. The positioning of the divs is as follows: top left, top right, bottom left, and bottom right. Additionally, there is another disabled div in the center panel control.

When any of the divs (top left, top right, bottom left, or bottom right) are clicked, all four divs should be disabled and their visibility set to false.

The clicked div should then appear in the center div within the panel.

Is it possible to achieve this functionality using only div clicks?

It's worth noting that there are no button controls available for use.

I aim to manage all interactions solely through clicking on the div elements.

Here is the code snippet:


<div class="img_top" style="margin-top: 40%">
    <div class="img_top_left">
        dgsdfg</div>
    <div class="img_top_right">
        dfgdsfg</div>
</div>
<div class="img_bottom" style="margin-top: 60%">
    <div class="img_bottom_left">
        dgsdfg</div>
    <div class="img_bottom_right">
        dfgdsfg</div>
</div>

<asp:Panel ID="Panel1" runat="server">
    <div class="img_center">
    </div>
</asp:Panel>

CSS Styles:


.img_center
{
    margin-top:50%;
    height:250px;
    background-color:Green;
}
.img_top_left
{
    height:250px;
    width:40%;
    float:left;
    background-color:Blue;
}
.img_bottom_right
{
    height:250px;
    margin-left:20%;
    width:40%;
    float:left;
    background-color:Orange;
}
.img_bottom_left
{
    height:250px;
    width:40%;
    float:left;
    background-color:Blue;
}
.img_top_right
{
    height:250px;
    margin-left:20%;
    width:40%;
    float:left;
    background-color:Orange;
}

Answer №1

If utilizing Jquery, you have the capability to achieve a similar effect:

    $(document).ready(function() {
        $('#toprightcenter').hide();
            $('#topleftcenter').hide();
            $('#bottomrightcenter').hide();
            $('#bottomleftcenter').hide();

$(window).load(function() {
    $('#topright').click(function() {
            $('#topright').hide();
            $('#topleft').hide();
            $('#bottomright').hide();
            $('#bottomleft').hide();
            $('#toprightcenter').toggle();
 return false;
});

This script will initially hide the central divs upon page load and then proceed to hide the other divs once clicking on the top right div, revealing the content within the toprightcenter div.

To successfully execute this code, it is essential to create center divs that store the content from all four corners, naming them accordingly such as #toprightcenter, #topleftcenter, etc.

Subsequently, duplicate the above function replacing 'topright' with 'topleft' in the click function section at the start, repeating this process until a code block is generated for each desired sequence of events.

I trust this guidance proves beneficial or assists in progressing towards your goal.

Answer №2

It is more common to utilize jQuery rather than ASP.NET for this task

Give this a try:

$('div').click(function () { // select all divs
  $('div').hide(); // hide all divs
  var divId = $(this).attr('id'); // get the id of the clicked div
  /* Use CSS properties to center it, for example */
  $(this).css({
    'margin', '10px' // add more as needed
  });
}

You can adjust the position of the element using CSS properties, while leaving the other elements in place! Therefore, you should use:

#div {
  position: absolute;
}

This allows you to change the position of the element relative to the others. You can also apply this property through jQuery using the .css() method.

Answer №3

Suppose you have assigned IDs to your div elements

$('div').click(function(){
    var currentId = $(this).attr('id')
    if(currentId == 'topleft' || currentId == 'topright' || currentId == 'bottomleft' || currentId == 'bottomright') {
        $(this).hide()
        $('#centrediv').html('<p>' + currentId + '</p>')
    };
});

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

Tips for creating the Next.js Image component to simulate the behavior of a standard <img> tag

I have been grappling with this issue for hours and I'm at a loss for what to do next. Here is how my Image component is wrapped: <div className={styles.featureImgContainer}> <Image src={ post.feature_image } alt={post.ti ...

Save the data retrieved from the success callback of a jQuery.ajax() request to be

Currently in my project, I am attempting to retrieve data from a PHP script. Most AJAX callback functions I have researched show examples where they "use" the data directly in the callback function itself. However, I am looking to fetch data and store it i ...

transfer information to the $_POST array using AJAX

When I click the 'submit' button to start playing music, my form data is not being sent to the global array $_POST. How can I fix this issue? Should I consider using AJAX and how would I implement it? The music plays, but the form data isn't ...

Received an error: xy is not defined, despite functionality being present

In my code, I am trying to update a value using this line of code: $('#'+name+userid).val(value); However, the userid variable seems to be undefined. I tried defining a new variable userid as a.attr('userid'), but then the value does no ...

Check the File Format (not just the Extension) prior to Uploading

When uploading a file within an HTML form, you can validate the extension using JQuery's Validation plugin: <form enctype="multipart/form-data" id="form-id"> <input type="file" name="file-id" id="file-id" /> </form> To validate ...

The menu on Android gets cut off by the status bar

Seems like an easy fix, our menu is getting cut off by the status bar on certain Android devices as shown in this screenshot. Any suggestions on how to resolve this issue? Could it be related to z-index properties? https://i.sstatic.net/Jh5SZ.png ...

Problems encountered when transferring information from jQuery to PHP through .ajax request

Hey there! I am currently working with Yii and facing an issue while trying to pass some data to a controller method called events. This is how my jQuery ajax call looks like: var objectToSend = { "categories" : [selectedOption],"datefrom" : month + "" + ...

Issue with jQuery serialize() function not returning expected results

My HTML form is structured as follows: <form class="form-horizontal" id="create_user" method="POST" action="#" accept-charset="UTF-8"> <span>Username</span><input required="true" type="text" name="username" id="username"> ...

Entities in Linq are capable of providing a list along with the average of ratings for each item

I have a query that retrieves information from multiple tables including RESTAURANT, CUISINE, CITY, and STARRATING to generate a list of restaurants along with their associated city, cuisine, and average rating. Here is the code I have written so far. An ...

Having difficulty linking the Jquery Deferred object with the Jquery 1.9.1 promise

I have been developing a framework that can add validation logic at runtime. This logic can include synchronous, asynchronous, Ajax calls, and timeouts. Below is the JavaScript code snippet: var Module = { Igniter: function (sender) { var getI ...

The specific inquiry cannot be processed within this current setting

Issue Description: System.Web.HttpException error due to unavailability of request in this context Source Error: Line 7: Private Sub Application_Start(sender As Object, e As EventArgs) Line 8: ' Caching the tracker image in memory Line 9: ...

Having trouble getting the submitHandler method in jQuery validation to work when submitting form data using $.ajax

When I use $.ajax to send data and validate with the jQuery validation plugin, the code looks like this: <div class="" id="ajax-form-msg1"></div> <form id="myform" action="load.php"> <input type="input" name="name" id="name" value ...

The div containing the background image does not resize properly when using media queries

page in question. I am currently working on a chess board project where each cell is represented by a div element. My goal is to make the board expand beyond certain minimum widths using media queries, but for some reason, this functionality is not working ...

Display the mobile keyboard without the presence of an input element

Attempting to display the mobile keyboard on my responsive site, I initially tried placing a hidden input with the placeholder "tap here." However, due to an event firing on this input that reloads the dom, I was unable to show the keyboard. I'm wond ...

The min-height property in CSS appears to be ineffective on Jelly Bean

In my current project developing an Android application, I have incorporated Webviews in certain activities and fragments. However, I encountered a perplexing issue when running the app on Jelly Bean (api 16 and 18) emulator - the css property min-height ...

Updating Sencha list itemTpl on the fly

Is there a way to dynamically change the itemTpl in a Sencha list to adjust the visibility of a column based on certain conditions? Your assistance would be greatly appreciated. ...

Using jQuery to apply CSS styles to specific tags

I am attempting to retrieve the href of a pair of links and, based on the href value, I aim to apply specific CSS styles to that particular link. Below is the code I have used: $('.pane-menu-block-2 .menu li a').each(function(){ if($('a[hre ...

Determine the overall price of the items in the shopping cart and automatically show it at the bottom without the need for manual entry

Creating a checkout form that displays the total cost of products, subtotal, GST cost, delivery cost, and overall price. The goal is to calculate the total by adding together the costs of all products with the "price" class (may need ids) at a 15% increase ...

"jQuery Datatable for server-side processing is specifically designed to function properly only when initially loading

I've scoured the web, including Google, Datatable docs, Datatable ... and I couldn't find a solution. I'm using Symfony 4 and following this guide, https://datatables.net/examples/server_side/simple.html and https://datatables.net/manual/ser ...

Error message: PHP/jQuery - Cannot save the cropped image

Currently, I am working on a webpage that enables users to crop an image and save it to their file. However, after clicking the crop button and receiving an alert message stating "upload success", the image is not being saved in the designated folder. It s ...