Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #18056

Re: Simple question about div show or hide

Newsgroups comp.lang.javascript
Subject Re: Simple question about div show or hide
From "Evertjan." <exxjxw.hannivoort@inter.nl.net>
References <b7e6883d-fe02-41ca-b4e8-89cfaccde7f6@googlegroups.com> <s6ute8l104jskskikjlj8sg3ik15nfjvpv@4ax.com>
Date 2013-01-10 19:37 +0100
Message-ID <XnsA144C7965E81Feejj99@194.109.133.133> (permalink)

Show all headers | View raw


Hans-Georg Michna wrote on 10 jan 2013 in comp.lang.javascript:

> On Wed, 9 Jan 2013 12:54:59 -0800 (PST), justaguy wrote:
> 
>> document.getElementById('t').style.display='inline';
> 
> To avoid problems you could set it to '' instead of 'inline'.
> 
> Moreover, you can do something like
> 
> var st = document.getElementById('t').style;
> 
> Then you can just use
> 
> st.display = '';
> 
> or
> 
> st.display = 'none';
> 
> and don't have to find the same element again multiple times.

Try these:

==================== test.html ================
<script type='text/javascript'>

function swapStyle(el, styl, v1, v2) {
  var st = el.style;
  st[styl] = (st[styl] != v1) ?v1 :v2;
};

function swapStyleGebi(id, styl, v1, v2) {
  var st = document.getElementById(id).style;
  st[styl] = (st[styl] != v1) ?v1 :v2;
};

</script>

<div 
onclick = "swapStyle(this, 'color', 'red', 'black')" id=d>
Colour swap
</div>

<div 
onclick = "swapStyleGebi('d', 'display', 'none', 'block')">
Display swap
</div>
=============================================



-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Simple question about div show or hide justaguy <lichunshen84@gmail.com> - 2013-01-09 12:54 -0800
  Re: Simple question about div show or hide Scott Sauyet <scott.sauyet@gmail.com> - 2013-01-09 13:29 -0800
  Re: Simple question about div show or hide Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2013-01-09 22:44 +0100
    Re: Simple question about div show or hide justaguy <lichunshen84@gmail.com> - 2013-01-09 14:25 -0800
      Re: Simple question about div show or hide Richard Yates <richard@yatesguitar.com> - 2013-01-09 14:47 -0800
    Re: Simple question about div show or hide Martin Leese <please@see.Web.for.e-mail.INVALID> - 2013-01-10 09:52 -0700
      Re: Simple question about div show or hide Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2013-01-10 21:02 +0100
  Re: Simple question about div show or hide Hans-Georg Michna <hans-georgNoEmailPlease@michna.com> - 2013-01-10 18:26 +0100
    Re: Simple question about div show or hide "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-01-10 19:37 +0100
  Re: Simple question about div show or hide Danny <dann90038@gmail.com> - 2013-01-10 12:47 -0800

csiph-web