Creating a grid of divs by adding additional divs to a main div

http://jsfiddle.net/prashanthcr/cv5c3cah/1/

Here is a snippet of HTML code:

<h2 id="header">Etch-a-Sketch!</h2>
<div id="wrapper">
    <div id="grid"></div>
</div>
<input id="size" type="number" value="10">
<button id="button">New Grid</button>

This is the JavaScript (jQuery) code:

$(document).ready(function() {
    var cellsPerSide = $("#size").val();
    var cellSize = $("#grid").width() / cellsPerSide;
    $(".cell").css({"width": cellSize, "height": cellSize, "opacity": "1"})

    for (var i = 0; i < cellsPerSide * cellsPerSide; i++) {
        $("#grid").append("<div class='cell'></div>");
    }

});

And here is the CSS code:

.cell {
    background-color: red;
}

The author experimented with fixed and dynamic sizes for the grid cells. The static solution worked, but the dynamic one did not display the divs as intended. Suggestions on making it work or achieving a grid of cells with no gaps are welcome.

The attempt to use display:inline-block resulted in extra space between lines, which was not desired.

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 transferring the input text box value to angularjs when clicking on the text box

Here is the HTML code snippet: <tr ng-repeat="c in client"> <td><input type="text" id="id" value="{{c.id}}" onclick="display();"></input></td> <td><input type="text" value="{{c.fname}}"></td> </ ...

Using $_GET superglobal in WordPress to retrieve data from URL parameters

Let me explain... I've designed a button that, when clicked, opens a link such as https://www.something.com/something/?term=something or [initially, I suspected it was a URL issue... so I experimented with other options] Like:- https://www.somet ...

J Query Easy Color Chooser - ideal for choosing background colors

As I venture into the world of HTML coding, I am struggling to implement a jQuery simple color picker to change the background color. Despite my efforts with various color pickers, I can't seem to make the background and display box respond correctly. ...

JQuery range events failing to trigger

Whenever a user adjusts the JQuery range control, I want to update a value. Despite my attempts to follow an example provided here, I have not been successful. $(document).ready(function () { alert('ready1'); //This alert appears when t ...

jQuery function duplicates row in table

I am trying to utilize jQuery to generate a table, but I seem to be encountering an issue with my code: function showGrid(url, container, columns, page) { jQuery(container).empty(); var tr = jQuery("<tr class=\"mobileGridHeader\"> ...

Using Angular filters, it is possible to eliminate DOM elements without relying on jQuery

As I dive into learning Angular, I am grasping the basics quite well. However, my limited knowledge of JavaScript seems to be hindering my progress. Currently, I am working on a feed that pulls data from a JSON file. Within this data, there is a string co ...

Prevent any sliding animations of content when the button is triggered

I've implemented a basic slideToggle functionality in jQuery. You can check out the code on JSFiddle here: $(document).ready(function() { $(".panel_button").on('click', function() { $(".panel").slideUp(); var targetPanel = $(thi ...

The hyperlink refuses to open in a new tab

The jQuery BlockUI plugin is causing me some confusion. My goal is to include a clickable link within the content locked by the plugin, but no matter what I try - including adding target="_blank" - it just won't direct to the specified URL. Any sugg ...

What is the process for deselecting a checkbox?

I am facing a situation where I need to uncheck a checkbox that is always checked based on user input from another section of my form. Specifically, I have implemented an onChange="functionName" event on a select box. Can someone guide me on how to accom ...

jQuery and Ajax drop-down list with unique select tag identifiers

I found a useful practice resource here If you want to see a working demo, you can check it out here Repeating the code happens here: jQuery Code: $(document).ready(function() { //$('#loader').hide(); $('.parent ...

Creating horizontal bars using div elements with no content

Is there a way to create two divs using Bootstrap 4, one with content and the other empty as shown in the wireframe example below? This is my attempt: <div class="icons_div"> <div class="row"> <div class="col-sm-2"> <div ...

"Excessive use of Javascript setInterval combined with frequent ajax calls is causing significant

I have integrated the setInterval() function into my JavaScript code to make an AJAX call every 2 minutes. However, I noticed that this is causing the website to slow down over time. The website is built using Node.js. After doing some research, I came acr ...

What is the best way to display the full dropup-menu content while the scroll bar is active?

I've been working on a project where I need to ensure that the dropup-menu content is fully visible when the scroll bar is in use. Currently, the dropup-menu content isn't displaying completely when scrolling up or down. To enable the scrollbar ...

Creating a stationary div in Internet Explorer 10 Mobile

Is there a way to create a fixed div that is compatible with IE10 Mobile on Windows Phone 8? Currently, I have been using the following code: <div style="position:fixed;width:100%;background-color:blue;"> test </div> This solution is only ...

Locate elements with Jquery after displaying HTML content

I am encountering an issue with the code snippet below: tblBody = $('#tbody'); tblBody.html(rowsStr.join('')); var lines = tblBody.find("tr"); The array rowsStr contains strings that create tr and td tags. Sometimes, when I use tblB ...

Exploring deeper in highmaps - tips for deleting a data series

My goal is to create a drilldown map on Highmaps utilizing the example provided at this link. I have successfully adapted this example with my own data for a different country. The following code is from the example: $(function () { // Code here ...

Utilize overlib text in your jQuery projects

As I develop my personal Grease Monkey userscript, I find myself in need of modifying the overlib text through the use of jQuery. Here's a representation of it in HTML code: <div class="expbar" onmouseover="return overlib('Some text',HA ...

The web application automatically updates the URL upon triggering a POST or submission event

I have a page named .aspx located in a directory called "Graphics". Within that page (DisplayArena.aspx), I utilize jQuery.load to "load" another .aspx page into a div as shown below: //in DisplayArena.aspx //loading from the folder "BossEncounters" $(do ...

Unable to fix position: sticky issue following Angular 15 update

Following the angular material update to version 15, many of us experienced issues with CSS changes breaking. This also affected legacy code that included sticky headers. <div class="row"> <div class="col-12"> <di ...

Get rid of any unnecessary class on the element

I'm currently working on an image slider that displays before and after images when the user drags left to right. The issue I'm facing is that the 'draggable' class is being added not only to these images but also to my hero images. It ...