What could be causing the color to not appear in the textarea depending on the time condition?

I am attempting to dynamically change the color of my calendar blocks based on the current time.

I have created variables for various times in military format and compared them with the current time using a conditional statement. For instance, I have specified that 09:00 is less than the current time, which is 20:00. Despite this condition being true, the color change does not occur on the page as intended.

var dayTime = (moment().format('HH'))
var nine = '09';

console.log(nine);

var ten = '10';
var eleven = '11';
var twelve = '12';
var one = '13';
var two = '14';
var three = '15';
var four = '16';
var five = '17';

if (nine < dayTime) {
$('#nineText').addclass('past');
}
.past {
background-color: #ff6961;
color: white;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://momentjs.com/downloads/moment.js"></script>
<div class="time-block">
<div class="row">
<div class="col-1">
<p class='hour'>9AM</p>
</div>
<div class="col-10">
<textarea id='nineText' class="form-control" type='text' placeholder='placeholder' rows="2.9"></textarea>
</div>
<div class="col-md-1">
<button class="input-group-addon saveBtn btn-primary btn-lg" type="submit">Save</button>
</div>
</div>
</div>

My logic seems sound, but there must be a step that I am overlooking.

Answer №1

Remember to use the method addClass instead of addclass. Make sure your class name matches what you specified in the question.

var dayTime = new Date().getHours();
var nine = '09';
console.log(nine);
console.log("Current hours "  + dayTime);
var ten = '10';
var eleven = '11';
var twelve = '12';
var one = '13';
var two = '14';
var three = '15';
var four = '16';
var five = '17';

if (parseInt(nine) <= parseInt(dayTime)){
$('#nineText').addClass('present');
}
.present {
background-color: #ff6961;
color: white;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class = "time-block">
  <div class ="row">
      <div class="col-1">
          <p class='hour'>9AM</p>
      </div>
      <div class="col-10">
          <textarea id ='nineText'  class="form-control"  type='text' placeholder= 'placeholder'  rows="2.9"></textarea>
      </div>
      <div class="col-md-1">
          <button class="input-group-addon saveBtn btn-primary btn-lg" type="submit">Save</button>
      </div>
  </div>
</div>

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

Change the behavior of a submit button to trigger a custom JavaScript function instead

I am faced with a challenge where I need to override the default functionality of a button in code that cannot be altered. Instead, I must ensure that when the button is clicked, a custom JavaScript method is called rather than submitting the form as it no ...

Issues encountered with JavaScript when trying to use the jQuery API

I'm trying to fetch random quotes using a Mashape API, but when I click the button, nothing happens. I've included the JS and HTML code below. Can anyone spot an issue with the JS code? The quote is not displaying in the div. Thank you! $(' ...

leveraging express.js middleware alongside jwt and express-jwt for secured authentication in express framework

I am encountering an issue while using the express-jwt to create a custom middleware. The error message persists as follows: app.use(expressJwt({ secret: SECRET, algorithms: ['HS256']}).unless({path: ['/login', '/']})); ...

What are the implications of an unidentified callback function with parameters?

Check out this snippet: const fs = require('fs'); fs.readFile('foo.txt', 'utf8', (error, data) => { if (error) { throw new Error(error); } console.log(data); }); Can you figure out where the anonymous callback is recei ...

React state is null and void

Experimenting with React and working on creating a basic chat application that will be linked to Firebase. I currently have one ChatApp container and one UserInput component. ChatApp -> import React from 'react'; import UserInput from &apos ...

What could be causing the fluctuation in ui-grid height as I scroll horizontally?

After using ui-grid in numerous projects without any issues, I recently encountered a strange issue when working with a large number of columns. With approximately 50 columns, as I scroll from left to right in order to view the columns that are off-screen ...

What is the method to retrieve a JSON encoding from the render function in Symfony2?

Struggling to implement ajax in symfony, as it poses a challenge. There's a form in twig where a value is obtained for searching a product in the database: This is the form in twig: <form id="myForm" method="post" action="{{ path('my_app_gre ...

Issue With ASP.Net Dropdown List Not Showing My Selected Option Again

I am facing an issue with retrieving the initially selected value from a dropdown list on my ASP.NET form. The form consists of 4 pages and the data is being stored in the session successfully. HTML for the 1st Page Including DropDownList <asp:DropDow ...

Activate the clicked tab in the Bootstrap navbar when selected

I have gone through similar posts, but I am unable to get mine to work. My goal is to activate the clicked tab. Here is what my bootstrap navbar looks like in HTML: <div class="navbar navbar-default" role="navigation"> <div class="container" ...

Guide on transforming Json information into the preferred layout and iterating through the loop

Currently, I am diving deep into the world of JSON and feeling a bit puzzled by data formats, arrays, objects, and strings. First things first, I'm in need of data structured like this (on a jQuery page). Would this be considered an object or an arra ...

Ensure that both the previous and next carousel icons appear in the same color when either hovered over or visited

When I hover or click on one of the carousel items, they change to a darker color than their original appearance. I want them to maintain the same color in both states, but I'm struggling to make this adjustment. I've experimented with changing t ...

Component is not rendering with React-router

Having some trouble with this code snippet I'm trying to implement. React is not rendering the component and I can't figure out why. I have included react-router from a CDN. Any assistance would be greatly appreciated. import { Router, Route, Li ...

The function in PHP does not arbitrarily return a boolean value

After creating a template file for WordPress, I encountered an issue with a function that I wrote. Despite ensuring that the two variables are different (as I confirmed by printing them), the function consistently returns true. Even after testing and attem ...

Hold off on advancing until the particular text is found in the DOM element

One of the challenges I'm facing is creating a function that waits for specific text to change before returning a value: function getElementText() { while(isLoading()) { } return $('#element').text(); } function isLoading() { ...

Mist Conceals Celestial View (THREE.JS R76)

I have a cylindrical camera setup with fog to hide the end of the tube. However, I am trying to make the skybox visible through the alpha map sides of the cylinder. The current issue is that the fog is blocking the visibility and I'm looking for a sol ...

What is the process for transforming the search bar into an icon located at the top of a WordPress site?

For the past few weeks, I've been attempting to convert the search bar on my website (which is currently a plugin) into an icon positioned near the header. I've experimented with modifying the child theme's functions.php, the parent theme&a ...

The functionality of Kendo Autocomplete is currently experiencing issues when used in Mozilla Firefox

Currently, I am implementing the Kendo Autocomplete feature on a textbox to retrieve a list of cities. The functionality works perfectly fine on Chrome, but when I tested it on Mozilla, the list flickers - appearing and disappearing rapidly. Below is the ...

Issue encountered while attempting to deactivate button until numerical data is entered in the OTP field using Vuejs

otp_value: '', isFadeout: false, verifyOtp() { this.disabled = true; this.otpBtnClicked = false; this.verified = true; }, <input class="o ...

What is the proper method for setting up handlers in functional React components?

My knowledge of JavaScript tells me that there are three different ways to define functions. Let's take a look at them: 1. Declaration function handleEvent(e) {} 2. Assignment var handleEvent = function(e) {} 3. Arrow var handleEvent = (e) => ...

What is the best way to minimize the number of files being referenced for compilation?

Is there a way to reference less files in my project without including their styling in the final CSS output? @import(reference) filename.less When I try this, it seems to include the styles from filename.less in the final compiled CSS. Is there a better ...