Adding static text after animated text in CSS can be achieved by using a combination of key

I've recently delved into the world of web development and could use some guidance. I am facing a challenge where I have two texts in the HTML (p tag) on the same line, with one linked to JS using an "ID" and the other to CSS using a "Class" along with keyframes. Additionally, I am struggling to add a static text that displays after the animated text.

My goal is - To have the first text animate by default, and upon triggering JS actions, such as clicking a button, the second text should display a static text on the same line alongside the first text.

Here is my code:

JavaScript
CSS
HTML

let secondText = document.getElementById("second-text");
let a = 1;
let b = 5;

let c = a + b;
let result = "";

function startAction() {
  if (c <= 12) {
    result = "December";
  } else {
    result = "Not-Exists";
  }
  secondText.textContent = result;

  console.log(result);
}
#second-text {
  margin: 30px;
  font-size: 20px;
  font-weight: 700;
}

.first-text {
  margin: 30px;
  font-size: 20px;
  font-weight: 700;
  animation: typing 10s steps(19) infinite;
  overflow: hidden;
  white-space: nowrap;
  border-right: 2px solid #111;
  width: 19ch;
}
@keyframes typing {
  0% {
    width: 0ch;
  }
  50% {
    width: 19ch;
  }
  100% {
    width: 0ch;
  }
}
<p class="first-text" id="second-text">Welcome To My Page</p>

<button onclick="startAction()">Action</button>

I would appreciate any insight on what might be causing issues in my code.

Answer №1

Are you seeking this specific information?

let secondText = document.getElementById("second-text");
let a = 1;
let b = 5;

let c = a + b;
let result = "";

function startAction() {
 document.getElementById("second-text").classList.remove("first-text");
 document.getElementById("second-text").classList.add("newClass"); 
  if (c <= 12) {
    result = "December";
  } else {
    result = "Not-Exists";
  }
  secondText.textContent = result;

  console.log(result);
}
.first-text {
  margin: 30px;
  font-size: 20px;
  font-weight: 700;
  animation: typing 10s steps(19) infinite;
  overflow: hidden;
  white-space: nowrap;
  border-right: 2px solid #111;
  width: 19ch;
}
 .newClass{
  margin: 30px;
  font-size: 20px;
  font-weight: 700; 
  overflow: hidden;
  white-space: nowrap; 
  width: 19ch;
  }
@keyframes typing {
  0% {
    width: 0ch;
  }
  50% {
    width: 19ch;
  }
  100% {
    width: 0ch;
  }
}
<p class="first-text" id="second-text">Welcome To My Page</p>

<button onclick="startAction()">Action</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

unable to see the response after making an ajax request

I am encountering an issue with my nodejs application. It is sending responses with the header set as application/json. The client successfully receives a 200 OK status in response to its http ajax request, and I can also view the JSON response from the Re ...

`Why is my table row not appearing horizontally in Cordova/Phonegap?`

Why is my tr tag displaying buttons vertically instead of horizontally? A similar code works properly on jsfiddle What am I doing wrong? Here is my HTML: <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta name="form ...

Ways to terminate session using ajax when input is empty; Notice of an undefined variable

Warning: Variable 'outputname' is undefined There is a query in the file memberSearch.php. I want to echo the $outputname variable in another PHP file inside an input tag. However, when I try to echo ($outputname) in another file, it returns an ...

Steps to insert additional characters surrounding the innerhtml of an h2 element

After extensive searching, I still can't seem to figure this out. It's possible I'm overlooking something very obvious, and for that, I apologize. My current challenge involves adding two specific characters to multiple h2 elements. While I ...

Passing a value from a dropdown menu to a different template page in Django 1.6

I am looking to capture the user's selection from a dropdown field and use it to filter profile listings on the next page. The goal is for the user to choose an option from the dropdown on the index.html page, submit the form, and then be redirected t ...

How to access array objects in JSON by using a specified key

If we consider the following HTML structure: <form action="#" action="get"> <select name="college" id="college" onchange="selection('college', 'course')"> <option value="">Select an Option</option> ...

Incorporate HTML or Word-formatted text into your website design

We are in the process of transitioning an Intranet application from ASP to ASP.NET. The current ASP version makes heavy use of frames, which I aim to eliminate in the new version. One specific module within the application deals with documents, and I have ...

Verify whether the div contains a height style. If it does, refrain from altering the height

In my design, I have a main container div with a set height (which may change depending on css media query). There is also a parent div where the user can input a height value (usually in percentage, occasionally in pixels). The child divs allow the user t ...

Why is the second row of inputs not displaying in Vue.js?

I am currently developing a Single Page Application (SPA) that includes options with variants, similar to the image shown below: [1]: https://i.sstatic.net/82I5U.png However, I have encountered an issue where the second row of inputs for variants is not b ...

Error TS2322: Cannot assign type 'Promise<Hero | undefined>' to type 'Promise<Hero>'

I am currently studying angular4 using the angular tutorial. Here is a function to retrieve a hero from a service: @Injectable() export class HeroService { getHeroes(): Promise<Hero[]> { return new Promise(resolve => { // ...

retrieve the path of any module within an npm monorepo

I am working on a project using an NPM monorepo structure which utilizes ECMAScript Modules (ESM): <root> |_package.json |_node_modules/ | |_luxon (1.28.0) |_packages/ |_pack1 | |_node_modules/ | | |_luxon (3.0.1) | |_main.js |_pack2 |_ ...

Enhance an Array directly through the prototype method

I have developed a custom method to clean up an array by removing duplicates and sorting it. It was successful and the code looked like this: // Example array. var names = [ 'Lara', 'Lucy', 'Alexa', 'Vanessa', &apo ...

Email JS indicating that the provided Public Key is invalid

I'm currently utilizing email js for handling form submissions in React, and encountered this notification: "The Public Key is invalid. For the correct ID, please visit here, " Although I've double-checked the public key, I seem to b ...

Mysterious Charcoal Colored Button Background on Mobile Exclusively using Bootstrap

I am facing an issue with the navigation bar on my website. The navigation bar code is as follows: <nav class="text-center"> <button class="btn nav-button color-house" type="button"><%= link_to "House", home_house_path, class: "co ...

My React application came to an unexpected halt with an error message stating: "TypeError: Cannot read properties of undefined (reading 'prototype')"

Everything was running smoothly with my app until I encountered this error without making any significant changes: TypeError: Cannot read properties of undefined (reading 'prototype') (anonymous function) .../client/node_modules/express/lib/resp ...

Android 403 error encountered when trying to access the Google Sign-In client script from the accounts.google.com URL with async defer attributes included

When I run my Angular app (built with the Ionic framework) locally in a browser, everything works fine. However, when I try running it through Android Studio or package and push it to my mobile phone, I encounter a 403 error. The issue seems to be related ...

Creating classes in an Express controller using CoffeeScript is essential for organizing and structuring your code

I have a controller named api/meeting/meeting.controller.coffee class Talker constructor: (@name) -> talk: -> console.log "Talker name is" + @name module.exports.meeting = (req, res, next) -> talker = new Talker 'Bob' t ...

Steps for deactivating jQuery slider control until radio button is selected:

Looking to deactivate the operation of jQuery UI sliders until a radio button is selected. Despite my efforts, I have been unsuccessful in achieving this task and could use some guidance. For reference, here is a link to the code: http://jsfiddle.net/nlem3 ...

Storage in Ionic and variable management

Hello, I'm struggling to assign the returned value from a promise to an external variable. Despite several attempts, I have not been successful. export class TestPage { test:any; constructor(private storage: Storage) { storage.get('t ...

Tips for creating a star program using Angular 2+

Create an Angular 2+ code snippet that will print asterisks (*) in a list on button click. When the button is clicked, it should add one more asterisk to the list each time. For example: Button Click 1 - Output: * Button Click 2 - Output: ** Button Cl ...