Link to home
Start Free TrialLog in
Avatar of winbiz
winbiz

asked on

Why does Javascript display property "block" not always hide my object?

Hi everyone,

1) I'm using the following method to cause an ojbect on my form to either be hidden or displayed.

//  this.oInput.style.display = "none";
//  this.oInput.style.display = "block";

2) However the block property does not always cause the object to be hidden. Particularly when my form is first loaded!. It's incredibily frustrating!!

3) Can someone tell me what difference between the "block" and  : style.visibility = 'hidden' methods is. And if there are any other javascript methods to hide and control an object is.

I'd really appreciate some enlightenment on on this one.

Thanks in advance everyone.

Regards,

winbiz
Avatar of maUru
maUru

Hi winbiz,


Cheers!
err, shouldnt you use

this.oInput.style.display = "";
2) However the block property does not always cause the object to be hidden. Particularly when my form is first loaded!. It's incredibily frustrating!!
block doesnt 'hide' it tells css how to display it (block or inline)

3) Can someone tell me what difference between the "block" and  : style.visibility = 'hidden' methods is. And if there are any other javascript methods to hide and control an object is.

usually for hiding in javascript you do:

//  this.oInput.style.display = "none";

and to show its:
//  this.oInput.style.display = "";
ASKER CERTIFIED SOLUTION
Avatar of callrs
callrs

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
P.S. There's two accepted answeres there. Try mine first...
Avatar of winbiz

ASKER

Callrs!!!

Thank you very, very, very much!

Learning in an informal manner as I am/have can make it difficult to recognize that more than one method for accomplishing is available, let alone the implications each method has.

You little script did both succinctly and clearly.

Regards,

wb
: )

Welcome. But see my profile...

winbiz,

dont ask a question but then accept an answer which does not actually answer the actual question

so in the future, ask: how can i make a switch on, switch off toggle for 2 divs using javascript

which i could have easily posted as my first response but it wasnt what you asked for.

that way you do not waste my time.
Asker has asked "Can someone tell me what difference between the "block" and  : style.visibility = 'hidden' methods is. And if there are any other javascript methods to hide and control an object"

Just as a picture is worth a thousand words, a working example, with simplified neatly ordered code, helps more than any explanation. In fact it  IS the explanation as the mind can see instantly "what the difference" is. Even the link that I provide in the example agrees: "This is a test page to CLARIFY the difference..." (emphasis added).

Asker asked "I'd really appreciate some enlightenment on on this one"
And she got it.

Would you rather sit through a lecture on, for example, the difference between a  "ThingAMaJig" and a "RingAMaThig", or have it shown to you, so that it's SELF-EXPLANATORY?

A demo that  explains itself saves us a lot of time when we can see the difference instantly...

Cheers.

- R.S.
And as a bonus, asker now has a full working template to quickly deploy in own code. So the end purpose in asking-- to be able to code with understanding -- is better fulfilled.
>> I'd really appreciate some enlightenment on on this one.

he is asking /why/ not /how/

>> However the block property does not always cause the object to be hidden. Particularly when my form is first loaded!. It's incredibily frustrating!!
>> A demo that  explains itself saves us a lot of time when we can see the difference instantly...

i mean, if you were to ask winbiz right now why did your code do what he said in point 2), he would not know what to say

callrs, my problem is not the answer given, it was that winbiz is not a coder, and therefore will take the code, use it and not realise/care why or why not his code didnt work, and thats all good.

but he asked the /wrong/ question for the answer he was looking for, thereby wasting my time and im want to point it out to him (not about wasting my time, but so in the future he can ask questions that are specific to what he is looking for so experts who spend their free time on this site dont get annoyed).

say the thing was reversed, he asked 'how can i write a showhide function' and you spend 20 minutes writing a whole function out, only for him to say, no no i dont want code i want to know ' what difference between the "block" and  : style.visibility = 'hidden' methods is'

ah fuck it im tired.
It takes longer time to write well, to be specific, etc., especially when faced with non-working code. It's up to 'experts' to direct, to help in the best & quickest way possible. Asker had a need, expressed it, and accepted the answer that best met that need.

But anyway, we can debate the point all night, not what I want to do.

I feel you do deserve some points, which you can get by saying a word or two here: https://www.experts-exchange.com/questions/21899994/Points-for-maUru.html

: )
heh callrs, thanks but i dont care about the points, i just want winbiz (and others) to be more specific in the future, because it helps everyone.