Is it possible to generate a coordinate grid comprised of clickable div elements with HTML, CSS, and Javascript - with the option to utilize JQuery if necessary?

Here is a link to the code on JFiddle: http://jsfiddle.net/4v2n7wk9/1/

<html>
<head>
<title>Example of Grid Buttons</title>
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.1/jquery-ui.js"></script>
<style>
div{
    display:inline-block;
    margin-left:-2px;
    margin-right:-2px;
    margin-top:-4px;
    margin-bottom:-4px;
    position:relative;
}

.inl{
    position:absolute;
    display:block;
}

.top{
    position:absolute;
    z-index:auto;
}

.feature_layer{
    position:absolute;
    z-index:-2;
}

.unit_layer{
    position:absolute;
    z-index:-1;
}

.first_column{
    position:absolute;
    margin-left:0;
}

.second_column{
    position:absolute;
    margin-left:64px;
}

.third_column{
    position:absolute;
    margin-left:128px;
}

#first_row{
    position:absolute;
    margin-top:0;
}

#second_row{
    position:absolute;
    margin-top:64px;
}

#third_row{
    position:absolute;
    margin-top:128px;
}
</style>
</head>
<body>
<script>
$(document).ready(function(){
    $("#first_row").on("click",function(){
        console.log("First row clicked.");
    });
    $("#second_row").on("click",function(){
        console.log("Second row clicked.");
    });
    $("#third_row").on("click",function(){
        console.log("Third row clicked.");
    });

    $(".first_column").on("click",function(){
        console.log("First column clicked.");
    });
    $(".second_column").on("click",function(){
        console.log("Second column clicked.");
    });
    $(".third_column").on("click",function(){
        console.log("Third column clicked.");
    });
});
</script>
Menu Below<br>
<div id="first_row" class="first_column"> <img src="http://i.imgur.com/WZfLsKD.gif"/> </div>
<div id="second_row" class="first_column"> <img src="http://i.imgur.com/WZfLsKD.gif"/> </div>
<div id="third_row" class="first_column"> <img src="http://i.imgur.com/WZfLsKD.gif"/> </div>

<div class="second_column" id="first_row" > <img src="http://i.imgur.com/WZfLsKD.gif"/> </div>
<div id="second_row" class="second_column"> <img src="http://i.imgur.com/WZfLsKD.gif"/> </div>
<div id="third_row" class="second_column"> <img src="http://i.imgur.com/WZfLsKD.gif"/> </div>

<div id="first_row" class="third_column"> <img src="http://i.imgur.com/WZfLsKD.gif"/> </div>
<div id="second_row" class="third_column"> <img " src="http://i.imgur.com/WZfLsKD.gif"/> </div>
<div id="third_row" class="third_column"> <img src="http://i.imgur.com/WZfLsKD.gif"/> </div>
</body>
</html>

I've hit a wall trying to solve this conundrum. The example above shows a simple layout of nine image divs in a three-by-three grid with different row and column identifiers. However, while the first column functions correctly, the two columns to the right only register column IDs in the console log.

This issue seems straightforward, but I can't seem to figure it out. Any assistance would be greatly appreciated. Thank you.

*To view console logs, right-click on JSFiddle's result screen (bottom-right of the four panes) and select Inspect Element in Chrome. The console records console.log() calls along with other information.

Answer №1

Here is an updated example from JSFiddle where classes are used instead of ids for the rows: http://jsfiddle.net/troygizzi/4v2n7wk9/5/

Some parts of the code have been modified below.

HTML:

<div class="first_row first_column"> <img src="http://i.imgur.com/WZfLsKD.gif"/> </div>
<div class="second_row first_column"> <img src="http://i.imgur.com/WZfLsKD.gif"/> </div>
<div class="third_row first_column"> <img src="http://i.imgur.com/WZfLsKD.gif"/> </div>

<div class="first_row second_column"  > <img src="http://i.imgur.com/WZfLsKD.gif"/> </div>
<div class="second_row second_column"> <img src="http://i.imgur.com/WZfLsKD.gif"/> </div>
<div class="third_row second_column"> <img src="http://i.imgur.com/WZfLsKD.gif"/> </div>

<div class="first_row third_column"> <img src="http://i.imgur.com/WZfLsKD.gif"/> </div>
<div class="second_row third_column"> <img " src="http://i.imgur.com/WZfLsKD.gif"/> </div>
<div class="third_row third_column"> <img src="http://i.imgur.com/WZfLsKD.gif"/> </div>

JavaScript:

$(".first_row").on("click",function(){
    console.log("First row clicked.");
});
$(".second_row").on("click",function(){
    console.log("Second row clicked.");
});
$(".third_row").on("click",function(){
    console.log("Third row clicked.");
});

CSS:

.first_row{
    position:absolute;
    margin-top:0;
}

.second_row{
    position:absolute;
    margin-top:64px;
}

.third_row{
    position:absolute;
    margin-top:128px;
}

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

jquery refreshing tool

Hey there, I've got this script http://jsbin.com/ajaneh that uses Ajax when performing actions. $.ajax({ type: "POST", url: domain+"/home/register_working_time/", dataType: 'json', data: d ...

Why isn't the correct component being shown by react-router?

I have encountered an issue with my code. When I type localhost:8080 in the browser, it displays the App.js component as expected. However, upon navigating to localhost:8080/#/hello, it still shows the App.js component instead of hello.js. Interestingly, ...

Uncovering secret divs with the power of jQuery timing upon reload

Currently, I am in the process of developing a custom Wordpress theme for my blog which includes an overlay-container. When a button is clicked, this container slides in from the top and pushes down the entire page. To achieve this functionality, I am uti ...

What is the best way to ensure that a <label> remains vertically aligned with its <form>?

I'm struggling to incorporate their suggestions into my design. How can I align my label to the left of my input field on the same line? Also, I'm a beginner in coding so please excuse any mistakes in my code: body { background-color: #f5f ...

Storing retrieved data in React without using Redux involves using either the Context API or

When using Redux, I have a common store where fetched data is stored. For example, if I navigate away from my videos page (/videos) and then return to it, the videos are still available in the videos reducer. This allows me to show the user already loaded ...

Using AngularJS to interact with neighboring DOM elements

Imagine a scenario where there is a div containing 5 img elements. When one of these img elements is hovered over, the goal is to change the class of all the elements on its left side. <div id="stars"> <img src="star.png" data-rating="1" ng- ...

Create a fresh instance of an object in node.js by utilizing the require/new method

I am encountering a beginner problem with node.js where I cannot seem to create objects using the 'new' operator in the index.js file. My goal is to define a simple Person object within a Person.js file, located in the same directory as my index ...

Searching the database to find if the username is already in use with MEAN

Help needed with signup controller code! app.controller('SignupController', function ($scope, $http, $window) { $scope.submitSignup = function () { var newUser = { username: $scope.username, ...

Encountering no automatic refresh feature in Next.js

Encountering an issue with Next.js where the local host index page doesn't automatically refresh whenever a change is made. To provide some context, I initiated a Next.js application using npx create-next-app --use-npm. After starting the local serve ...

Having trouble properly wrapping divs using nextUntil() method

I am facing an issue with wrapping elements in HTML. The code snippet I have tried is not giving me the desired result. $('.cards .card-image').each(function() { $(this).nextUntil(".card-description").addBack().wrapAll("<div class='c ...

Dealing with two AJAX posts on a single PHP page, where both posts are being sent to the same page without specifying a URL

Managing 2 posts on the same page to execute 2 different PHP scripts is my current challenge. Upon successful validation of all field data in the first POST, a new block will be activated. Within this new block, additional inputs will be displayed. Once t ...

When using an HTML dropdown select to display a list of generated users, only the value of the first user

I have a template that fetches a list of users from the database, and each user row contains a dropdown select option to change their user type (this is an admin page). My goal is to make the dropdowns submit the changes asynchronously. Currently, I can on ...

Is there a way to store JSON data in a constant variable using Node Fetch without encountering the error TypeError [ERR_INVALID_URL]: Invalid URL?

In my current NodeJS project, I am working on extracting data from a JSON file and then sending it to a constant variable in my app2.mjs. The goal is to organize this data into an array of objects and eventually save it into a database. However, when tryin ...

What is the best way to set up localStorage with a multi-dimensional array

I am struggling with modifying my local storage and it's taking up a lot of my time. Initially, I set it up like this: localStorage.setItem('example','{"data": []}'); It was working fine, but now I need to structure it like the ...

Stop the color buffer from being automatically cleared in WebGL

Removing gl.clearColor(c[0],c[1],c[2],1.0); gl.clear(gl.COLOR_BUFFER_BIT ); does not stop the screen from getting cleared at the start of the next draw cycle. Is there a method to avoid this situation? I am aiming for an overpaint effect. ...

What is the method of passing raw JavaScript code to functions in the Yii framework?

When creating a checkbox using the CHtml method, I need to execute specific JavaScript code before and after an AJAX request. Here's the code snippet: echo CHtml::checkBox('markComplete', FALSE, array( 'class' => & ...

Using jQuery to align a div element to the top of the viewport

Is there a way to keep the #lightbox div positioned at the top of the viewport consistently? $(document).ready(function(){ $('.mehr').click(function() { $("body").css("overflow", "hidden"); $('#lightbox').css({'visibil ...

Invoke the componentDidMount() method in a React Component that is not a subclass of React.Component

I have a react component that I render later in my index.js file index.js import React from 'react'; import ReactDOM from 'react-dom'; import App from './App'; ReactDOM.render( <React.StrictMode> <App /> ...

Retrieve the current user input value from a jQuery autocomplete combobox

How can I retrieve the current input value that the user has typed? The issue arises when the combobox doesn't maintain focus, as it's possible for the form to be submitted by pressing Enter without selecting an option from the dropdown list. In ...

Alignment and spacing in a flexible direction

Hello, I am developing a bar app. <AppBar position="sticky" className={classes.appBar} > <Container maxWidth="lg"> <Toolbar className={classes.root}> <Typography noWrap> <img src={require("./node ...