The Role of Filling in a Process

I am looking to create a rectangle that fills up gradually every day, increasing by 1% each time. This is the basic concept.

My main struggle is figuring out how to fill it up. I need the rectangle to increase by 1% of its width each day. So essentially, I only need to change the background color of 1/100th of the rectangle's width.

For instance, if my rectangle has a width of 100px, I would like to update the background of just the first 1px. It's similar to a battery indicator... Any ideas on how to achieve this? I prefer using HTML or CSS, but I'm open to JavaScript/jQuery solutions as well.

Thank you.

Answer №1

I created a simple jQuery code that accomplishes the task you described. I inserted a div with a width of 0px inside another div with a width of 100px, and then used JavaScript to dynamically adjust the width of the first div based on the second one. Below is the code snippet:

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
  console.log($("#firstDiv"));
  $("#secondDiv").css("width", parseInt($("#firstDiv").css("width")) / 2 + "px");
})
</script>
</head>
<body>

<div id="firstDiv" style="border: 1px solid red; width: 100px; height: 100px;">
  <div id="secondDiv" style="background-color: blue; width: 0px; height: 100px"></div>
</div>

</body>
</html>

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

Creating dynamic input fields in JavaScript by using class-based methods

I have a requirement to dynamically duplicate a couple of fields whenever the user clicks on the Add button and then capture the data from these fields. While searching online, I came across various tutorials like Tutorial which demonstrate how to create n ...

Retrieve a key based on a selected value from a PHP array using jQuery

I'm having trouble figuring out how to sync a select dropdown state field in a user registration plugin on my WordPress site with the billing_state field in WooCommerce. The select dropdown has an array of states, but WooCommerce uses state abbreviati ...

What could be causing this Ajax request to come back with an error?

I am facing an issue with an AJAX request to a WordPress PHP function. The strange part is that the response is being treated as an error. However, when I check the error log, the responseText contains the requested JSON data, the status is 200, and statu ...

Simple request results in an error

I have been experimenting with the Electrolyte dependency injection library, but I am encountering an error even when trying a simple script that requires it. I haven't come across any discussions or problems similar to mine in relation to this issue ...

Unable to dynamically change the value of the submit button using angular.js

I'm facing an issue with setting the submit button value dynamically using Angular.js. The code I've written below explains my problem. <body ng-controller="MainCtrl"> <input type="submit" value="{{ !model ? 'reset' : mod ...

Sending data to a React Dialog component using the OnClick event

I am a beginner learning React.js and currently experimenting with passing parameters to a dialog box using onclick events. <IconButton className={classes.approvebutton} onClick={() => handleDialogClick("approve",1)}> <ThumbU ...

What is the best way to vertically align a pseudo element image using CSS?

After looking for similar questions, none of the answers seem to be working for my specific issue. This is what I'm struggling with: I am attempting to insert and center a decorative bracket image before and after certain content in the following man ...

The Node.js express seems to be unable to fetch the css and js files

Sharing my main.ts file in which I am facing issues with linking my css and js files. view image import express from 'express'; import {Request,Response} from 'express'; import expressSession from 'express-session'; import pat ...

Is the background element rather than its input being focused upon when clicking in the link tool's dialog within ContentTools?

I am utilizing ContentTools within a Bootstrap modal. The issue I am facing is that when I select text and click the hyperlink tool, the link dialog pops up but immediately focuses on an element in the background (such as the modal close button). This prev ...

express-validator, no validation errors have been found so far

How can I verify if a given string is in the format of an email address? Here's a snippet of code that attempts to do so: req.checkBody('email', 'Invalid email address').isEmail(); var validationErrors = req.validationErrors(); i ...

A stateless component in React must always return a valid React element or null

I am a beginner with ReactJS and I am facing an issue. My goal is to showcase Hello world using the code snippet provided below, however, I keep encountering this error message: Can someone guide me on what I might be overlooking? The following is the c ...

Unlocking the power of keys in manipulating JSONP objects

i am uncertain about the accuracy of my title, as i am unsure how to label the task at hand... "modifiers":{"agility":{"type":"attribute","displayname":"agi","value":46}} forms a part of a jsonp callback that is received from this source. i am attempting ...

Using JQuery to Update Text, Link, and Icon in a Bootstrap Button Group

I have a Bootstrap Button group with a split button dropdown. My goal is to change the text, href, and icon on the button when an option is selected from the dropdown. I am able to change the text successfully, but I'm having trouble updating the HREF ...

Selecting content loaded via Ajax using jQuery

I recently implemented a library that I found at this website According to the documentation, I need to use the following syntax: autosize($('textarea#description')); This works fine for regular elements, but when my textarea is loaded via aja ...

CakePHP includes built-in jQuery pagination and sorting functionality

Does CakePHP have built-in jQuery pagination and sorting functionality similar to regular jQuery? I have searched online but couldn't find relevant information. Can someone please point me in the right direction? Thank you, Himanshu Sharma ...

Console is displaying an error message stating that the $http.post function is returning

Just diving into angular and I've set up a controller to fetch data from a factory that's loaded with an $http.get method connecting to a RESTful API: videoModule.factory('myFactory', function($http){ var factory = {}; facto ...

Why won't my div tag show conditionally with AngularJS ng-show?

I'm having trouble displaying a div tag on a form based on the boolean flag specified in ng-show. Unfortunately, the div is not showing up at all. Here's what I've tried so far without success. Any assistance would be greatly appreciated! F ...

Utilizing DataTables and Ajax call to refresh table data with Json response

My table is dynamically generated using Thymeleaf and I want to update its contents with jQuery. <table class="table table-hover" id="main-table"> <thead class="thead-inverse"> <tr> <th class="c ...

The ReactJS Material Table Tree mode experiences delays when new row data is introduced

My Reactjs app utilizes the material-table widget within a component: render() { return ( <div> <Row> <MaterialTable title="Mon équipement" style={{ width: "100%", margin: "0%" }} ...

I'm encountering an issue where the this.props object is undefined even though I've passed actions to mapDispatchToProps. What could

Summary: The issue I'm facing is that in the LoginForm component, this.props is showing as undefined even though I have passed actions in mapDispatchToProps. I've debugged by setting breakpoints in the connect function and confirmed that the act ...