473,324 Members | 2,002 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,324 software developers and data experts.

How to show and hide element using display attribute?

oranoos3000
107 100+
i read below text that say about initial state display in css and relate with show and hide dom element

do the below text describe this meaning that if we dont write display for element and hide that , it's display convert to hide and if again show that do convert display that to block or initial value related to html? for example for span if we hide span and again show that it's display convert to block or inline?

if for the same span i has writen display to block in initial css how about?

text i write about that is as follow as
" if an element starts as hidden by having its display style property value
explicitly set to none, the show() command will always set its display style prop-
erty value to block. That’s even if the element would typically default to inline
for its display value—as would a <span> element, for example. If the element
starts out without an explicitly declared display value, and we use the jQuery
hide() command to hide it, the show() command will remember the original
value and restore it to that original display state.
So it’s usually a good idea not to use style attributes on the elements we want
initially hidden, but to apply the hide() command to them in the page’s ready
handler. This prevents them from being displayed on the client, and also makes
sure everything is in a known initial state and will behave as expected during sub-
sequent hide and show operations
"
thanks alot
Nov 6 '10 #1
6 4319
gits
5,390 Expert Mod 4TB
what it really does depends on the implementation of the hide() and show() methods ... so what ist the context of all that? jQuery or whatever?
Nov 6 '10 #2
oranoos3000
107 100+
hi
i'm sorry ,i forget say i use hide and show jquery method
Nov 6 '10 #3
gits
5,390 Expert Mod 4TB
the jQuery-show() method executes:
Expand|Select|Wrap|Line Numbers
  1. show: function( speed, easing, callback ) {
  2.         if ( speed || speed === 0 ) {
  3.             return this.animate( genFx("show", 3), speed, easing, callback);
  4.         } else {
  5.             for ( var i = 0, j = this.length; i < j; i++ ) {
  6.                 // Reset the inline display of this element to learn if it is
  7.                 // being hidden by cascaded rules or not
  8.                 if ( !jQuery.data(this[i], "olddisplay") && this[i].style.display === "none" ) {
  9.                     this[i].style.display = "";
  10.                 }
  11.  
  12.                 // Set elements which have been overridden with display: none
  13.                 // in a stylesheet to whatever the default browser style is
  14.                 // for such an element
  15.                 if ( this[i].style.display === "" && jQuery.css( this[i], "display" ) === "none" ) {
  16.                     jQuery.data(this[i], "olddisplay", defaultDisplay(this[i].nodeName));
  17.                 }
  18.             }
  19.  
  20.             // Set the display of most of the elements in a second loop
  21.             // to avoid the constant reflow
  22.             for ( i = 0; i < j; i++ ) {
  23.                 this[i].style.display = jQuery.data(this[i], "olddisplay") || "";
  24.             }
  25.  
  26.             return this;
  27.         }
so if there was a display attribute before using hide() which stores that as olddisplay-attribute then this old value will be restored on show() otherwise it will set display to an empty string.
Nov 6 '10 #4
oranoos3000
107 100+
hi
if i dont set display in css as explicit for example i have a span and dont identify display in css , now hide that then show that , do it's display become inline(because this is inline element) or block(for this is default is jquery)?

thanks alot for your help
Nov 7 '10 #5
oranoos3000
107 100+
hi

i found my answer that is as follow as
if element is hidden via jquery earn previous display that it can be default value for display(that is inline or block)
but if element is hidden other than jquery it's display is set to block
be successful
Nov 7 '10 #6
gits
5,390 Expert Mod 4TB
added the entire function in question - it seems to check the parent nodes for any old display property - if there was none then it should applies the default browser display property ... the hide() method stores the current property so that it can be restored by the show() method from the olddisplay property.

glad that you found your answer :) ...
Nov 7 '10 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Mad Scientist Jr | last post by:
Through messing around I got IE6 (win xp) to show/hide a table row. I gave my <TR> an ID of "trRow" and trRow.style.display='none'; hides it trRow.style.display='block'; displays it (will any...
10
by: oLE | last post by:
I would like to add some javascript to show/hide a certain row of a table. The first row of the table contain the hyperlink that calls the javascript the second row is the one i want to show/hide...
3
by: alex | last post by:
I'd like to have a show/hide widget on my web site, kind of like "show details" / "hide details" in Google Groups. Is there a tutorial explaining how to make them? Google's is a bit complex and...
4
by: bridgemanusa | last post by:
Hi All: I have a very long page of html that I want to take portions and hide them in divs, then show when a link is clicked. I have the hide show part working when the link is clicked, however...
7
by: FP | last post by:
I'm new to Java Script. I'm displaying comments people have made. Below each persons' comment I want to add 2 buttons "Reply" and "Amend". Clicking "Reply" would display an empty text field...
1
by: asilverpeach | last post by:
Hey Guys! Found some great scripts here on this topic but have to make to changes to the code that I can't seem to figure out. First, In the following code clicking on the headers shows the...
6
by: Norman | last post by:
Hello, I have a working Show / Hide form, that works on FF, but what I would like to do is to be able to display one part when a user clicks on one radio button and display another part when the...
4
by: Dan | last post by:
Hi, I know how to show and hide text, but I want to make it so that the page shifts up when I hide my text. Right now with the simple code, it only leaves a blank space. Thanks, Daniel
1
by: shapper | last post by:
Hello, I have the following function: function show(id) { var allIds = , ids, i=0; while(ids = allIds) { document.getElementById(ids).style.display=ids==id?'block':'none'; } }
2
by: Scott McNeill | last post by:
I have created a form with show/hide on a couple of fields. However, this hidden info is not posting back when I click submit. Can someone help? Source code <?xml version="1.0"...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
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
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...

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.