Display the input once the button is pressed

On my home page, I need to hide the <input> element until the button is clicked. When designing my typing game for mobile users, I included an input field that should only be visible upon clicking the button.

Answer №1

Upon inspection, it appears that the input fields are currently visible and not hidden. To address this, you can start by hiding them using a style attribute such as "display:none". After doing so, include the following code snippet within your onclick function:

$("#buttonID").on("click", function(){
 $("#inputID").show();

Answer №2

If you know the button's ID and the input's ID, you can achieve the following:

const theButton = document.querySelector("#buttonID")
const theInput = document.querySelector("#inputID");

theButton.addEventListener("click", () => theInput.style.display = "block");

Remember to initially hide the input using display: none; in your CSS file.

Answer №3

When creating a webpage in html, it is essential to include an <input> and a <button>.

<input type="text" name="info" id="info" class="">
<button id="showInfo">Show Input</button>

To style the elements using css, add the class .active and set the input's display property to none.

input {
   display: none;
}

.active {
   display: block;
}

The first step involves selecting the <input> and <div> elements from the DOM. Next, an event listener needs to be added for the click event on the <button>.

const input = document.querySelector('input#info');
const showInput = document.querySelector('button#showInfo');

showInput.addEventListener('click', () => {
   input.classList.toggle('active')
})

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

Create high-quality PDFs from HTML pages

On my HTML page, I have a Bootstrap container with responsive images. When the page is viewed in a browser, I'd like to give users the option to print the page and receive a well-rendered PDF. However, I'm encountering issues where some images ar ...

Steps to reveal a child element when the parent is set to overflow:hidden

There seems to be an issue with a child element having overflow:visible; while the parent element has overflow:hidden;. The height of the child element exceeds that of the parent element. Why is the child element hidden even when its overflow property is ...

How should .has(), .get() and .set() be properly implemented for a JavaScript Map() within an ExpressJS server?

Feeling thrown off by javascript Map()? My query revolves around javascript Map() - the set, get, and has() functions. Despite thinking I was an expert, it seems I still have things to learn... Situation: I'm dealing with a 'global' map sto ...

What is the best way to generate multiple progress bars by leveraging a for loop?

Exploring the code snippet below, I've been creating a progress bar that reacts to specific data input in array form. However, the issue I've encountered is that the code only generates a single progress bar. How can I incorporate this into my f ...

Do I have to additionally check the data type using typeof when implementing PropTypes in my code?

I have a custom method called onNotifyChange that is triggered in the onChange event of an input element. This method has been defined with a PropType of func. MyComponent.propTypes = { onNotifyChange: PropTypes.func, } When invoking the onNotifyCha ...

Empty nested Map in POST request

I am currently working on a springboot application with a React/Typescript frontend. I have defined two interfaces and created an object based on these interfaces. export interface Order { customer_id: number; date: Date; total: number; sp ...

Positioning pictures in front of a backdrop

I'm facing an issue with a section that slides into view with a blue background. I want to add a picture in the upper left corner, but it's barely visible and the blue background disappears. Here's a snippet of the HTML code: <header id ...

Retrieving download links from <a> tags in Python

I need help extracting the contents of a <p> tag. Here is an example of the HTML: <p><a href="https://requiredlink.com" download>Download<span class="caret"> Here's what I've tried so far: r = requests.get("https://abc. ...

What are some techniques for reducing the number of pages in my Carousel?

I need help figuring out how to set a limit of noOfPages for the number of pages per carousel. The functions in my code below don't implement this and I'm unsure how to do it. const itemsPerPage = 6; const [page, setPage] = React.useState(1); ...

Tips for comparing two arrays of test dsa das dsge a:

My task is to compare and evaluate two arrays to determine if they both have the property 'approved' set to true. ...

What is the best way to ensure balance between columns in Bootstrap 4?

Hello everyone! I am currently working on ensuring that all the columns in my table have equal width, except for the update and delete columns which should remain as they are. I'm utilizing Bootstrap 4.5.2 for this task. Below is the code snippet of ...

Session is necessary in Express.js to be able to access specific routes

One of the challenges I face with my app is ensuring that certain pages can only be accessed by logged-in users. Currently, I have implemented the following code to address this issue: app.use((req, res, next) => { if (req.session.username) { ap ...

Google Maps API Error: Marker Title Not Found

I am currently developing a map feature that allows users to click on it and generate new markers. These markers should display some information in the sidebar, including latitude, longitude, and a title. The issue I am facing is with the title of the firs ...

Encountering the error "SCRIPT438: Object does not have support for this property or method" in Internet Explorer 10

I have a JavaScript function that changes the form action and submits it afterward. $(document).on('click','#q7', function(event) { event.preventDefault(); document.forms[0].action = "questionnaireQ7AvenantsAction.do?method=rec ...

Automating the process of uploading a file to a Github repository using JavaScript and HTML

Recently, I've been tinkering with updating a file in my GitHub repository using code to set up an automated system for pushing changes without manual intervention. My approach involved creating a function that utilizes a GitHub access token to ' ...

Restricting specific devices and browsers access to my website

Is there an effective way to prevent outdated browser versions and mobile devices from accessing my website? I want to provide a message informing them of the compatible browsers for the site. ...

Creating PHP functions that return a JSON string when invoked - a simple guide

I have created a script that contains various functionalities, including fetching data from a database and encoding it into JSON. However, I want to be able to call different functions to execute these scripts separately. When I attempted to define and c ...

Chaining promises allows you to utilize the outcome of one request to make another

I've been experimenting with ES6 in node.js and want to transition from using callbacks to promises. I created a test project to fetch an oauth2 token from an api/endpoint, refresh it, and then revoke it. My code snippet is as follows: const oauth2Ad ...

Triggering a Dialogflow Chat Window with a click on a Material-UI Floating Action Button in a ReactJS application

I have encountered an issue in my code where I am attempting to toggle the display of a Dialogflow Chat Window, <ChatWidget />, when a user clicks on the Material-UI Floating Action Button, <FloatingActionButton/>. The default state is set to f ...

Blank area located at the bottom of the document

I'm having trouble designing a webpage without a scroll bar because there isn't much content to display on the page. I've tried searching for solutions and following steps to fix the issue, but I haven't had any success. If anyone can a ...