473,320 Members | 1,884 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,320 software developers and data experts.

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.getElementById(id)
elem.id.style = 'display: none;'
}
</script>

Paul
Sep 12 '05 #1
5 14974
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.getElementById(id)
elem.id.style = 'display: none;'
}
</script>

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

OR

function test(id){
document.getElementById(id).style.display = "none"
}
Mick
Sep 12 '05 #2
code is wrong

"PJ6" <no****@nowhere.net> wrote in message
news:RohVe.3887$3b6.186@trndny07...
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.getElementById(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.getElementById(id)
if (elem.display == "block")
{
elem.display = "none"
}
else
{
elem.display = "block"
}
alert(elem.display)
}

Paul

"Mick White" <mw***********@rochester.rr.com> wrote in message
news:IM******************@twister.nyroc.rr.com...
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.getElementById(id)
elem.id.style = 'display: none;'
}
</script>

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

OR

function test(id){
document.getElementById(id).style.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.getElementById(id)
if (elem.display == "block")
fix #1: if(elem.style.display == "block")
{
elem.display = "none"
fix #2: elem.style.display = "none";
}
else
{
elem.display = "block"
fix #3: elem.style.display = "block";
}
alert(elem.display)
}

Paul


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

elem.style.display = (elem.style.display == "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.getElementById(id)
if (elem.display == "block")
{
elem.display = "none"
}
else
{
elem.display = "block"
}
alert(elem.display)
}


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.getElementById) {
var elem = document.getElementById(id)
if (elem.style) {
elem.style.display = ('' == elem.style.display)? 'none' : '';
}
}
}

[...]

--
Rob
Sep 13 '05 #6

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

Similar topics

1
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. ...
2
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. ...
7
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+...
18
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...
2
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 =...
1
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...
5
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...
1
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"...
8
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...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
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: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.