Box Pattern with Pop-Up Modal

Check out the grid of squares I've coded below:

<div class='square-container'>
    <div class='square'></div>
    <div class='square'></div>
    <div class='square'></div>
    <div class='square'></div>
    <div class='square'></div>
    <div class='square'></div>
    <div class='square'></div>
    <div class='square'></div>
    <div class='square'></div>
    <div class='square'></div>
    <div class='square'></div>
    <div class='square'></div>
.....
</div>

If a user clicks on any square, I'd like a modal popup to appear. The styling should be similar to this https://codepen.io/khaag/pen/sbcou

How can I implement this feature with my current code? Also, how can I make this grid more dynamic than it is now?

Answer №1

Create a click event handler like this:

$(".square").on("click", function(){
    //////////// Your modal window code
});

Here's an example using tomloprodModal:

$(".square").on("click", function(){
    TomloprodModal.create({
        bgColor: "#FFFFFF",
        textColor: "#333333",
        title: "Hi!", 
        content: "Nothing to say",
    });
});

View the updated JSfiddle here: https://jsfiddle.net/as1mpe25/2/

Answer №2

Make sure to incorporate jQuery into your HTML file, then insert the following script:

$(document).ready(function () {

$(".box").click(function(){
    alert("great job!");/* CUSTOMIZE THIS WITH YOUR SPECIFIC CODE */
});});

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

Can JavaScript be used to create a CSRF token and PHP to check its validity?

For my PHP projects, I have implemented a CSRF token generation system where the token is stored in the session and then compared with the $_POST['token'] request. Now, I need to replicate this functionality for GitHub Pages. While I have found a ...

Modify input value using jQuery upon moving to the next step

When you type into an input[text] and press the tab button, it automatically moves to the next input. If you fill out all the inputs and then want to re-fill them, the values will be highlighted in blue. However, I wanted to achieve this without having to ...

Is there a way to access or delete a randomly generated document ID in Firestore?

Need help with code to delete an item (current method not working) const docRef = firebase.firestore().collection('users').doc(firebase.auth().currentUser.uid) docRef.collection('tasks').doc(this.task.id).delete() ...

Configuring the AJAX URL for jQuery in a JS file within an ASP.NET MVC application

Currently, when making an Ajax call to an MVC action, I have my JavaScript code directly within the View instead of in a separate JS file. This makes it very convenient to include the URL in the ajax call using Url.Action(): var xhr = $.ajax({ url: ...

Encountering: error TS1128 - Expecting declaration or statement in a ReactJS and TypeScript application

My current code for the new component I created is causing this error to be thrown. Error: Failed to compile ./src/components/Hello.tsx (5,1): error TS1128: Declaration or statement expected. I've reviewed other solutions but haven't pinpointed ...

Utilizing AJAX to load a WAV file

One of the tasks I'm working on involves a collection of audio files. When a file from this list is clicked, I want JavaScript to load and display the waveform of that specific audio file. The following function is responsible for drawing the wavefor ...

Verify that the string does not have any repeating characters

I need assistance with a code that checks if all characters in a string are unique. I've noticed that the current code always returns true, which seems to be due to the false output of the if condition unless the first two characters in the sorted lis ...

Retrieve all elements from an array using jQuery

How do I extract all the elements from the array outside of the function? $.each(Basepath.Templates, function(i){ templateArray = new Array({title: Basepath.Templates[i].Template.name, src: 'view/'+Basepath.Templates[i].Template.id, descri ...

Retrieve 2 data points from an HTML source code using Python

I'm struggling to extract data-b following the term "Grab" from the unmodified webpage code. There are multiple <tr> tags on the page and I need to specifically target those containing "Need" just before </a>. While I initially tried using ...

Step-by-step guide on installing both Angular and Nodejs within a single folder

I'm diving into the world of NodeJs and Angular, and I recently created a simple NodeJS application following instructions from this link. However, I encountered an issue when trying to install Angular alongside NodeJS. After running ng new angular-cr ...

How to extract the value of an HTML text field by executing an SQL query in PHP

Sign In Page: Here is where users can enter their login credentials. Method used is PHP POST. <html> <head> <title> LOG IN </title> <style> body { text-align: center; } </style> </head> <body> <form ac ...

What is causing the QJsonValue(undefined) to be returned?

After sending a request to the API for bid price, I am receiving an undefined QJsonValue and unable to display it later. Can anyone help me pinpoint where I might be going wrong? { QApplication a(argc, argv); MainWindow w; w.show(); QNetwor ...

TypeScript struggling to recognize specified types when using a type that encompasses various types

I have a defined type structure that looks like this: export type MediaProps = ImageMediaProps | OembedProps; Following that, the types it references are defined as shown below: type SharedMediaProps = { /** Type of media */ type: "image" | "oembed"; ...

Tips for utilizing Jquery to manage a dropdown designed in button form

<div class="btn-group btn-grp-uk col-xs-12 "> <button id="colorList" type="button" class="btn-phn btn btn-dropdown-white- uk dropdown-toggle col-xs-12" data-toggle="dropdown">Red </button> <ul id="colordrop" class="dr ...

Convert a prototype code to jQuery using AJAX syntax

Seeking advice on my code syntax as I transition from Prototype to jQuery. I currently have both frameworks running simultaneously and aim to streamline all scripts into jQuery for improved page load efficiency and speed. Migrating from Prototype to jQue ...

Navigating through the Express.js routes incorrectly

I currently have 3 different express.js routes set up: app.get('/packages/:name', (req, res) => {...}); app.get('/packages/search/', (req, res) => {...}); app.get('/packages/search/:name', (req, res) => {...}); At t ...

Managing timestamps of creation and modification with Sequelize and Postgresql

As a newcomer to Sequelize, I find myself grappling with the intricacies of model timestamps management. Despite prior experience with another ORM in a different language, I'm struggling to wrap my head around how to automatically handle "createdAt" a ...

Unable to retrieve data using Ajax post method

I'm currently facing an issue where the data I am trying to send via post to a PHP file is not being posted. Instead, I am getting an empty array in the console log from the PHP file using var_dump. Here are the snippets of code I have in these files: ...

Two unnamed objects cannot be combined using the AsyncPipe

Currently, I am looking to implement an autocomplete feature using Angular Material in Angular 8. Below is a snippet of the code used in the TypeScript file: @Input() admins: User[]; userGroupOptions: Observable<User[]>; filterFormFG: FormGrou ...

Finding the label that is linked to the current DIV or textarea by its "for" property

I am working on a project that involves two elements - a textarea and a div. Each element has a label attached to it using the "for" attribute in HTML. <textarea id="txta_1" class="txta" cols="40" rows="3" onkeyup ...