473,382 Members | 1,512 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Make html button disappear with javascript?


Hi,

Is it possible to make a html button invisible using javascript?
I can certainly disable it:

var x=document.getElementById('button2');
x.disabled=true;
//x.type = 'hidden'; // read only?
//x.visible = false; // doesn't exist?

but is there a property i can (ab)use to make it invisible?

Thanks in advance.

Aug 5 '05 #1
3 31753
FantaJ wrote:
Hi,

Is it possible to make a html button invisible using javascript?
I can certainly disable it:

var x=document.getElementById('button2');
x.disabled=true;
//x.type = 'hidden'; // read only?
input type hidden is not the same as readonly - the user can't see it
so in that sense a readonly input it's not readable at all.
//x.visible = false; // doesn't exist?

but is there a property i can (ab)use to make it invisible?
You can hide elements using:

x.style.display = 'none';
or
x.style.visibility = 'hidden';

and to make it visible again:

x.style.display = '';
or
x.style.visibility = 'visible';

The difference is that display 'none' will make the element take up
zero space in the page and hence will likely affect page layout.
Visibility just hides/shows the element with no effect on page layout.

Thanks in advance.


--
Rob
Aug 5 '05 #2
Thanks Rob - just what i was looking for.

Aug 5 '05 #3
"FantaJ" <vi*********@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...

Hi,

Is it possible to make a html button invisible using javascript?
I can certainly disable it:

var x=document.getElementById('button2');
x.disabled=true;
//x.type = 'hidden'; // read only?
//x.visible = false; // doesn't exist?

but is there a property i can (ab)use to make it invisible?

Thanks in advance.


<button id="myButton">My Button</button>
<button onclick="toggleVisibility('myButton');">Hide/show My
Button</button>
<button onclick="toggleDisplay('myButton');">Remove/restore My
Button</button>
<script type="text/javascript">
function toggleDisplay(id) {
var el;
if (document.getElementById) {
el = document.getElementById(id);
} else if (document.all) {
el = document.all[id];
}

if (el && (el = el.style) && ('string' == typeof el.display)) {
el.display = ('none' == el.display ? '' : 'none');
}
}
function toggleVisibility(id) {
var el;
if (document.getElementById) {
el = document.getElementById(id);
} else if (document.all) {
el = document.all[id];
}

if (el && (el = el.style) && ('string' == typeof el.visibility)) {
el.visibility = ('hidden' == el.visibility ? 'visible' :
'hidden');
}
}
</script>
--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq
Aug 5 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Howard Jess | last post by:
: In HTML 4.01, a <button> element can take 1 of 3 types: type=submit (default) type=reset type=button The Javascript to create a button element dynamically is
4
by: Lau Alvin | last post by:
HI all , I want to make a button which have a server side OnClick event in .cs to update the DB. But I want it to have a client side onclick event to run a javascript popup too. And the...
3
by: Colin Graham | last post by:
I have been working on a form to update a database when i enter details and click a button. My issue is that some of the users click the button twice. I want to remove the button when i click it...
2
by: abarberis | last post by:
I am writing an asp.net application which is using image buttons for the interface. I have some buttons that have a enabled and disabled state. I have written javascript code to change the image on...
1
by: Bishoy George | last post by:
I have an html button that reads a text box and runs a javascript. I made a Required Validator on that text box , any web button follows that validator. My html button does not follow the...
4
by: Ryan | last post by:
Hello, I have a standard HTML button on an aspx web form that I have set to runat server. The button is named reset1 and its tag is as follows: <INPUT id="btnReset1" style="WIDTH: 60px;...
1
by: mdburton | last post by:
onclick="this.href='javascript:void(0)';this.disabled=1"> ive tried that, but it renders it useless and doesnt make it 'submit' it should be able to work, but so the user cannot submit it twice...
1
by: Mufasa | last post by:
I have a couple of radio buttons that make various things appear/disappear on the screen through JavaScript. All works great. Problem is I'll click a radio button, something will appear, I reload...
5
by: Susan Bricker | last post by:
I have a command button that I'd like to make "disappear" after being clicked and after the OnClick function has executed. I have tried changing the 'visible' attribute to false while within the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.