473,659 Members | 2,920 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

setting display to none

PJ6
When I call this function (I verified that I'm actually getting an element
with the id), why does IE ignore my attempt to set the display to none?

<script>
function test(id)
{
elem = document.getEle mentById(id)
elem.id.style = 'display: none;'
}
</script>

Paul
Sep 12 '05 #1
5 14985
PJ6 wrote:
When I call this function (I verified that I'm actually getting an element
with the id), why does IE ignore my attempt to set the display to none?

<script>
function test(id)
{
elem = document.getEle mentById(id)
elem.id.style = 'display: none;'
}
</script>

elem.style='dis play: none' //Not sure about this, though.

OR

function test(id){
document.getEle mentById(id).st yle.display = "none"
}
Mick
Sep 12 '05 #2
code is wrong

"PJ6" <no****@nowhere .net> wrote in message
news:RohVe.3887 $3b6.186@trndny 07...
When I call this function (I verified that I'm actually getting an element
with the id), why does IE ignore my attempt to set the display to none?

<script>
function test(id)
{
elem = document.getEle mentById(id)
elem.id.style = 'display: none;'
}
</script>

Paul

Sep 12 '05 #3
PJ6
Sorry, posted the wrong code...

The element's visibility is unchanged, although the alert tells me that its
property was properly set:

function test(id)
{
elem = document.getEle mentById(id)
if (elem.display == "block")
{
elem.display = "none"
}
else
{
elem.display = "block"
}
alert(elem.disp lay)
}

Paul

"Mick White" <mw***********@ rochester.rr.co m> wrote in message
news:IM******** **********@twis ter.nyroc.rr.co m...
PJ6 wrote:
When I call this function (I verified that I'm actually getting an
element with the id), why does IE ignore my attempt to set the display to
none?

<script>
function test(id)
{
elem = document.getEle mentById(id)
elem.id.style = 'display: none;'
}
</script>

elem.style='dis play: none' //Not sure about this, though.

OR

function test(id){
document.getEle mentById(id).st yle.display = "none"
}
Mick

Sep 12 '05 #4

PJ6 wrote:
Sorry, posted the wrong code...

The element's visibility is unchanged, although the alert tells me that its
property was properly set:

function test(id)
{
elem = document.getEle mentById(id)
if (elem.display == "block")
fix #1: if(elem.style.d isplay == "block")
{
elem.display = "none"
fix #2: elem.style.disp lay = "none";
}
else
{
elem.display = "block"
fix #3: elem.style.disp lay = "block";
}
alert(elem.disp lay)
}

Paul


Or if you would like to skip the if else statement altogether, you can
try something like this:

elem.style.disp lay = (elem.style.dis play == "block") ? "none" :
"block";

Hope this helps. :)

Sep 12 '05 #5
PJ6 wrote:
Sorry, posted the wrong code...

The element's visibility is unchanged, although the alert tells me that its
property was properly set:

function test(id)
{
elem = document.getEle mentById(id)
if (elem.display == "block")
{
elem.display = "none"
}
else
{
elem.display = "block"
}
alert(elem.disp lay)
}


The generic method is to toggle between 'none' and ''. That allows the
element to return to its default display (which may not be block and may
vary depending on the browser)

function showHide(id)
{
if (document.getEl ementById) {
var elem = document.getEle mentById(id)
if (elem.style) {
elem.style.disp lay = ('' == elem.style.disp lay)? 'none' : '';
}
}
}

[...]

--
Rob
Sep 13 '05 #6

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

Similar topics

1
11177
by: relaxedrob | last post by:
Howdy All! I am really stuck with this one - I want to completely create a table within JavaScript and insert it into the document, with onMouseOut and onMouseOver handlers in the table rows. Below is a sample of the code I have created. It all works in Netscape 7.1, but in IE 6 it shows the table but the handlers do not run. I can prove the handlers are even there (see the commented out alert command in the code) so why aren't they...
2
1931
by: Stewart | last post by:
Hi Experts. Please put the code sample below into an html document and take a look at in NN6+. One span should be shown while the other is hidden. Clicking the button should reverse this. However it doesn't. Removing the table structure from around the text fixes it, but I need the table structure (this is very simplified example). Hope someone can provide an alternative?
7
4848
by: Christopher J. Hahn | last post by:
I'm trying to use a script-generated form to submit to a script-generated iframe. The problem I'm running into is that the iframe is not assuming the name I assign it. IE6 on Win2000. FF1.0.2+ doesn't seem to have the problem. I'm doing: this.iframe = document.createElement( 'iframe' ); this.iframe.id = this.id + 'wh'; this.iframe.style.display = 'none';
18
18359
by: Dixie | last post by:
Can I set the Format property in a date/time field in code? Can I set the Input Mask in a date/time field in code? Can I set the Format of a Yes/No field to Checkbox in code? I am working on a remote update of tables and fields and can't find enough information on these things. Also, how do you index a field in code?
2
5184
by: Italian Pete | last post by:
Hi, I have a div control on an aspx page. I toggle the display property between 'block' and 'none' client side using the following javascript: function toggleDivOnOff(divID) { var x = document.getElementById(divID) x.style.display == 'block'? x.style.display='none' : x.style.display='block'; } In the code behind page, I want to use the value of the display property to
1
1110
by: ca | last post by:
I'm using about 30 blocks with links on my page, that can be opened or closed by users so they're able to select which links should be displayed on their 'personal' page. Just closing blocks for the first time works fine, but returning visitors that want to open or close a new block, lose their first setting, everything in the cookie is replaced. I use this code, anyone got an idea? I spent days figuring it out! It drives me crazy!
5
1376
by: verrice | last post by:
Hello, I'm writing a web application where I want to load bits of data at runtime from the client end (via AJAX). The loading of the data part works great, but for some reason anytime I try to impart a style setting (via either putting it inline, a CSS, or through javascript) the DIV completely ignores my setting. The setting most importantly I'm trying to apply is display: none, but none of them work. If I pre-create everything...
1
6476
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting" setting to be "E_ALL", notices are still not getting reported. The perms on my file are 664, with owner root and group root. The php.ini file is located at /usr/local/lib/php/php.ini. Any ideas why the setting does not seem to be having an effect? ...
8
10106
Toxinhead
by: Toxinhead | last post by:
Hey there guys I am having a little trouble with InnerHTML as i can't seem to figure out how to set the style of my div tag..... What im trying to do is that when i rollover pic1 it changes that pic and displays:block and visiblity:visible....and also changes pic2.. When the webpage is loaded it displays:none and visivlity:hidden also Heres my code:
0
8428
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8335
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8747
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8528
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6179
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2752
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1737
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.