Guide on Setting Multiple Strings to a CSS Property Using JavaScript

Just a heads up, I'm inquiring about multiple strings as opposed to multiple properties.

To be more specific, I am searching for a javascript/jquery method to modify the grid-template-areas property.

This particular property is capable of accepting multiple strings as its value. Take for example:

grid-template-areas: "a b b"
                     "a c d";

Answer №1

In order to successfully implement this, it is necessary to enclose the double quotes within the new grid-template-areas value. To achieve this, the new string should be bounded by single quotes. Here is a suggestion:

$('#example-element').css('grid-template-areas', '"a b b" "a b b" "a c c"');

It's important to note that this particular CSS rule will only function in modern browsers (excluding IE and older versions of Edge, <= 15)

$('button').click(function() {
  $('#example-element').css('grid-template-areas', '"a b b" "a b b" "a c c"');
});
#example-element {
  background-color: #eee;
  border: .75em solid;
  padding: .75em;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: repeat(3, minmax(40px, auto));
  grid-gap: 10px;
  width: 200px;
  grid-template-areas: "a a a" "b c c" "b c c";
}

#example-element :nth-child(1) {
  background-color: rgba(0, 0, 255, .2);
  border: 3px solid #00f;
  grid-area: a;
}

#example-element :nth-child(2) {
  background-color: rgba(255, 0, 200, .2);
  border: 3px solid #663399;
  grid-area: b;
}

#example-element :nth-child(3) {
  background-color: rgba(94, 255, 0, .2);
  border: 3px solid green;
  grid-area: c;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="example-container">
  <div id="example-element" class="transition-all">
    <div>One (a)</div>
    <div>Two (b)</div>
    <div>Three (c)</div>
  </div>
</div>

<button>Change layout</button>

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

Issue: This error occurs when attempting to double click on the diagram or a node but the show function for c is not recognized

I've encountered an issue with my gojs diagram. When I double click on it to edit the node name, I receive an error message. This problem occurred after upgrading my gojs version from v1.7.14 to v2.2.17. Below is the error stack trace: core.mjs:8453 E ...

Tips for implementing click events on multiple links iteratively

I am currently working on an asp.net application, and I have encountered an issue with the website names displayed on the dashboard. These names are retrieved from a SQL database and rendered to the view using the following code snippet: <h1>My Webs ...

What is the most effective method to store temporary data within a backend panel as a sub-option?

Greetings! I have been delving into the world of programming for a while now, striving to enhance my skills. Currently, I am faced with a dilemma: Within my backend application, administrators have the capability to add courses to our website. One featur ...

Merging two distinct arrays of objects in JavaScript can be achieved by utilizing various methods and

I have a challenge where I need to merge two arrays of objects in a nested way. var array1=[{ PersonalID: '11', qusetionNumber: '1', value: 'Something' }, { PersonalID: '12', qusetionNumber: '2& ...

Improved method for displaying information on a webpage using php and ajax technology

For my website-webservice project, I am required to fetch data from a database and perform calculations. I'm trying to determine the most efficient method for the user. Option 1: Utilize a XXXX.php file with AJAX functions to pass parameters and echo ...

Creating a webpage with a layout that features three full-length columns using

body { background-color: blueviolet; } .leftcolumn { width: 30%; height: 100%; float: left; background-color: brown; } .middlecolumn { float: left; background-color: yellowgreen; width: 60%; height: 100%; } <body> <div class= ...

Issue with Angular: event.key doesn't register as shft+tab when pressing Shift+Tab key

Our website features a dropdown menu that can be opened and closed by clicking, revealing a list of li items. However, we are currently experiencing an issue with keyboard focus navigation. When the Tab key is pressed, the focus properly moves from one li ...

Is there a way for me to manage the options that appear in both of my dual <select> elements?

Below is a snippet of code that I need help with: <p> <label>Dual Select</label> <span id="dualselect" class="dualselect"> <select name="select3" multiple="multiple" size="10"> <option value=""&g ...

Adding multiple instances of a JPanel class without replacing them

Currently, I am facing an issue where I have created a class that extends JPanel (shown below) and I am attempting to add multiple instances of this class to another JPanel. public class DOBGui extends JPanel { private static String dayList[] = {bunch o ...

"Troubleshooting when Firefox encounters an error with jQuery load

Having some issues with the function below for loading content into a target div. It's working fine on Chrome and Safari, but in Firefox (27.0.1, though likely all versions) it pops up an alert saying "0 error". $("#somediv").on('click', &a ...

When would you recommend setting localStorage in an Angular application?

In my EmployeesComponent, I have a list of employees with buttons for "Education Overview" and "Salary Overview" for each record. Clicking on an overview button takes me to the OverviewComponent, which then loads either the salary or education component. B ...

What could be causing the vertical alignment issue of this logo in its parent container?

I am having an issue with the vertical centering of the logo element within the <header> container on this page. It seems to be more pronounced on mobile devices compared to desktop. However, the second element (#forum-link) is aligning correctly. W ...

What is the process for storing a loaded model in three.js?

Working on a video game, I am encountering memory issues. Specifically, when loading 8 object models, I find that I am repeating them throughout the game map. This results in me having to load the same model multiple times in different locations on the map ...

Using Javascript to display a Div element for a short period of time when the mouse is clicked

Having some trouble creating a hidden colored block that appears after a mouse press anywhere on the page, stays visible for 2 seconds, and then disappears until another mouse press triggers it again. I've tried using '.click(function' and o ...

What steps do I need to take to create a delete button that will effectively remove a bookmark from an array?

Currently, I have created a form that allows users to input the website name and URL. Upon clicking the submit button, the output displays the website name along with two buttons: 1. one for visiting the site 2. another for removing the bookmark using on ...

Removing an element from a JSON array

I'm having trouble figuring out how to delete an element from a JSON array when the user clicks on a delete button. I suspect there might be an issue with the PHP script. javascript.js $(".delete").on('click', function(e){ var dele ...

Is transferring information to the factory from the controller feasible?

My factory definition: myAppServices.factory('ProfileData',['$http', function($http){ return{ newly_joined:function(callback){ $http.get( //myUrl will be an url from controller. myU ...

CSS media query to center the logo on mobile screens

As someone new to CSS and media queries, I'm reaching out for help from the experts. My challenge involves positioning a mat-toolbar with a menu button and app logo. The HTML code in question is as follows: <div class="toolbar"> <mat-too ...

Instructions for including dependencies from a globally installed npm package into a local package

I've noticed that although I have installed a few npm packages globally, none of them are showing up in any of my package.json files. What is the recommended npm command to automatically add these dependencies to all of my package.json files? ...

Exploring the fundamentals of JavaScript within the context of Express.JS

Can you please explain the distinction between these two blocks of code in JavaScript? app.get("/api/products/1", (req, res) => { const singleProduct = products.find((product) => { product.id === 1; }); res.json(singleProduct); }) ...