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

Home Posts Topics Members FAQ

How to show and hide element using display attribute?

oranoos3000
107 New Member
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 4346
gits
5,390 Recognized Expert Moderator Expert
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 New Member
hi
i'm sorry ,i forget say i use hide and show jquery method
Nov 6 '10 #3
gits
5,390 Recognized Expert Moderator Expert
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 New Member
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 New Member
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 Recognized Expert Moderator Expert
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
4142
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 value other than 'none' display on IE6?) I tried enclosing the <TR></TR> inside a <DIV> tag, and hiding that, but it doesn't work for some reason.
10
4643
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 with the javascript in a toggle fashion. the problem is a know very little javascript and have become incredibly frustrated because i went ahead thinking it was going to be like C. its not. I know i can use these lines to do the actual work:
3
2943
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 it's easy to get something wrong. If the browser does not support the required features, I want it to generate a completely static page with the "details" shown automatically.
4
4219
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 I would really like to use linked images instead to do the following: - When open.gif is clicked, the contents of the div show and open.gif is swapped with close.gif - subsequently, when close.gif is clicked, the div contents get hidden
7
29130
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 below the comment with a spell check & submit button. Clicking "Amend" would display the same buttons & text field but pre-populated with the original comment. Using Java Script how do I show / hide the text field in my list of comments but have...
1
16741
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 div information. I want a nested show hide element though. So when you click on "Do you have carpets to be cleaned?" Small Rooms & Medium Rooms appears (that I got working) But Then when you click on Small rooms or medium rooms i want the three lines...
6
4188
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 user clicks on the second radio button - here is the code which just shows / hides the whole form: <script type="text/javascript"> <!-- var dl_elements = new Array('dl_address_country',
4
3163
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
1173
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
2050
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" encoding="iso-8859-1"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Show Hide</title> <meta http-equiv="Content-Type"...
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
8851
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8751
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
8535
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,...
0
8629
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6181
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
4176
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
4338
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2757
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

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.