JIYIK CN >

Current Location:Home > Learning > WEB FRONT-END > HTML >

HTML Hide Buttons and Show Them Using Onclick

Author:JIYIK Last Updated:2025/04/19 Views:

This article will show you several ways to hide HTML buttons and make them visible using the onclick event.


Using the CSS display property to show hidden buttons in HTML

We can first hide the HTML button by setting its display property to none. We can then use JavaScript to set the display property to inline or blocked.

Displaying the property inline or block will display a hidden HTML button. The difference between the inline component display:inlineand display:blockthe block component is that the inline component can have two or more components in one row or line.

But a block component can have only one component in a row or line.

For example, create a button and name it Show. Set the button's onclick property to makeChange().

Click the Show button to call makeChange()the function. Then create three more buttons and name them Button1, Button2, and Button3.

Set the id of Button1 to b1, the id of Button2 to b2, and the id of Button3 to b3. In CSS, select the button by its id and set the display property to none.

Next, in JavaScript, create a function makeChange(). Inside the function, set the display property of each button to block.

Select a specific button as the first button by its id document.getElementById("b1"). Then, document.getElementById("b1")style.displayset the display by assigning to the block.

Repeat this for the other two buttons.

Sample code:

<button onclick="makeChange();">Show</button>
<button id="b1">Button1</button>
<button id="b2">Button2</button>
<button id="b3">Button3</button>
#b1, #b2, #b3 {
display: none;
}
function makeChange() {
    document.getElementById("b1").style.display = "block";
    document.getElementById("b2").style.display = "block";
    document.getElementById("b3").style.display = "block";
}

Show hidden button in HTML using jQuery show() method

We can also use jQuery show()function to show hidden HTML elements. show()The function only shows the selected HTML components whose display attribute is set to none.

It does not work on HTML elements with the visibility attribute set to none. We will use the same method as above to hide the button.

We will also reuse the HTML structure used in the above method.

After setting the button's display property to none, create a function in JavaScript makeChange(). Inside the function, select the button with ID and call the jQuery show()method $('#b1, #b2, #b3').show().

When the show button is clicked, the hidden button will be displayed. So, we can use jQuery show()method to show hidden button in HTML.

Sample code:

<button onclick="makeChange();">Show</button>
<button id="b1">Button1</button>
<button id="b2">Button2</button>
<button id="b3">Button3</button>
#b1, #b2, #b3 {
    display: none;
}
function makeChange() {
    $('#b1, #b2, #b3').show();
}

Previous: None

Next:Creating a currency input in HTML

For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.

Article URL:

Related Articles

Creating a currency input in HTML

Publish Date:2025/04/19 Views:119 Category:HTML

In this article, users will learn to input convert a normal HTML field into a currency input field. We will use HTML and jQuery to achieve our goal. input Convert plain to currency input in HTML using JavaScript toFixed() method In HTML, th

HTML 中的 role 属性

Publish Date:2023/05/06 Views:354 Category:HTML

本篇文章介绍 HTML role属性。HTML中 role 属性介绍,role 属性定义描述语义的 HTML 元素的角色。

在 HTML 中打印时分页

Publish Date:2023/05/06 Views:681 Category:HTML

本篇文章介绍如何在打印 HTML 页面或内容时强制分页。将 page-break-after 属性设置为 always Inside @media print to Page Break in HTML

在 HTML 中显示基于 Cookie 的图像

Publish Date:2023/05/06 Views:187 Category:HTML

本文介绍如何根据 HTML 中的 cookies 显示图像。根据 HTML 中设置的 Cookies 显示图像。问题陈述是我们需要根据网页传递的cookie来显示特定的图像。

在 HTML 中创建下载链接

Publish Date:2023/05/06 Views:382 Category:HTML

本文介绍如何在 HTML 中创建下载链接。使用 download 属性在 HTML 中创建下载链接.。我们可以使用 HTML 锚元素内的下载属性来创建下载链接。

HTML 中的 ::before 选择器

Publish Date:2023/05/06 Views:647 Category:HTML

本教程介绍 CSS ::before 伪元素。CSS ::before 伪元素。 ::before 选择器是一个 CSS 伪元素,我们可以使用它在一个或多个选定元素之前插入内容。 它默认是内联的。

在 HTML 中创建一个可滚动的 Div

Publish Date:2023/05/06 Views:232 Category:HTML

本篇文章介绍如何使 HTML div 可滚动。本文将介绍在 HTML 中使 div 可滚动的方法。 我们将探索垂直和水平滚动,并通过示例查看它们的实现。

HTML 显示箭头的代码

Publish Date:2023/05/06 Views:454 Category:HTML

一篇关于用于显示箭头的 Unicode 字符实体的紧凑文章。本文讨论使用 Unicode 字符实体在我们的 HTML 页面上显示不同的字符。 HTML 中使用了许多实体,但我们将重点学习表示上、下、左、右的三角

在 HTML 中启用和禁用复选框

Publish Date:2023/05/06 Views:290 Category:HTML

本篇文章介绍如何启用和禁用 HTML 中的复选框。HTML 中的复选框 复选框是一个交互式框,可以切换以表示肯定或否定。 它广泛用于表单和对话框。

Scan to Read All Tech Tutorials

Social Media
  • https://www.github.com/onmpw
  • qq:1244347461

Recommended

Tags

Scan the Code
Easier Access Tutorial