[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.javascript

Will insertBefore show it IMMEDIATELY?

bit-naughty

5/5/2016 6:07:00 AM

Hi,
I posted before about this in my ealier AppendSibling post, but I think no one heard me!

My question is, if I use this, as instructed:
insertBefore(newChild,
refChild) method.

Then will the element show up right away?
I DON'T want it to, I want it to remain invisible till I fiddle with it's CSS properties....


Thanks.
12 Answers

Ben Bacarisse

5/5/2016 9:17:00 AM

0

bit-naughty@hotmail.com writes:
<snip>
> My question is, if I use this, as instructed:
> insertBefore(newChild,
> refChild) method.
>
> Then will the element show up right away?
> I DON'T want it to, I want it to remain invisible till I fiddle with
> it's CSS properties....

Make sure that the initial properties render it invisible. Make it
visible (by whatever means you are using -- the position, visibility or
display properties) only when it is ready to be seen.

--
Ben.

Christoph M. Becker

5/6/2016 10:53:00 AM

0

bit-naughty@hotmail.com wrote:

> My question is, if I use this, as instructed:
> insertBefore(newChild,
> refChild) method.
>
> Then will the element show up right away?
> I DON'T want it to, I want it to remain invisible till I fiddle with it's CSS properties....

Consider to use CSS for styling instead of doing this by scripting. The
script would only add (or remove) a class name, then.

--
Christoph M. Becker

Evertjan.

5/6/2016 11:12:00 AM

0

"Christoph M. Becker" wrote on 06 May 2016 in comp.lang.javascript:
> bit-naughty@hotmail.com wrote:
>
>> My question is, if I use this, as instructed:
>> insertBefore(newChild,
>> refChild) method.
>>
>> Then will the element show up right away?
>> I DON'T want it to, I want it to remain invisible till I fiddle with
>> it's CSS properties....
>
> Consider to use CSS for styling instead of doing this by scripting. The
> script would only add (or remove) a class name, then.

On the other hand,
why wouldn't you [if you must] 'fiddle with it's CSS properties'
BEFORE you do the insertBefore()?

The Q sounds like "how to start masturbating after ejaculation?"
Or is that a bit too naughty for you?

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

Thomas 'PointedEars' Lahn

5/6/2016 12:08:00 PM

0

Christoph M. Becker wrote:

> bit-naughty@hotmail.com wrote:
>> My question is, if I use this, as instructed:
>> insertBefore(newChild,
>> refChild) method.
>>
>> Then will the element show up right away?
>> I DON'T want it to, I want it to remain invisible till I fiddle with it's
>> CSS properties....
>
> Consider to use CSS for styling instead of doing this by scripting. The
> script would only add (or remove) a class name, then.

False dilemma.

If newChild.style.display == "none" or
document.defaultView.getComputedStyle(newChild,
null).getPropertyValued("display") == "none", then even the dynamically
inserted element will not be displayed immediately, and it may be necessary,
depending on the use-case, to not have the element in the document tree from
the beginning.

However, you are correct that once the element is in the document tree,
toggling its â??displayâ? property (or other CSS properties) should be done
with class name toggling, unless there is a good reason not to.

--
PointedEars
FAQ: <http://PointedEars.... | SVN: <http://PointedEars.de...
Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-...
Please do not cc me. / Bitte keine Kopien per E-Mail.

Thomas 'PointedEars' Lahn

5/6/2016 12:09:00 PM

0

Christoph M. Becker wrote:

> bit-naughty@hotmail.com wrote:
>> My question is, if I use this, as instructed:
>> insertBefore(newChild,
>> refChild) method.
>>
>> Then will the element show up right away?
>> I DON'T want it to, I want it to remain invisible till I fiddle with it's
>> CSS properties....
>
> Consider to use CSS for styling instead of doing this by scripting. The
> script would only add (or remove) a class name, then.

False dilemma.

If newChild.style.display == "none" or
document.defaultView.getComputedStyle(newChild,
null).getPropertyValue("display") == "none", then even the dynamically
inserted element will not be displayed immediately, and it may be necessary,
depending on the use-case, to not have the element in the document tree from
the beginning.

However, you are correct that once the element is in the document tree,
toggling its â??displayâ? property (or other CSS properties) should be done
with class name toggling, unless there is a good reason not to.

--
PointedEars
FAQ: <http://PointedEars.... | SVN: <http://PointedEars.de...
Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-...
Please do not cc me. / Bitte keine Kopien per E-Mail.

Evertjan.

5/6/2016 2:11:00 PM

0

Thomas 'PointedEars' Lahn <PointedEars@web.de> wrote on 06 May 2016 in
comp.lang.javascript:

> However, you are correct that once the element is in the document tree,
> toggling its ? odisplay? property (or other CSS properties) should be
> done with class name toggling, unless there is a good reason not to.

Nonsense. That is just your personal dogma.

It can be done in many ways, unless there is a good reason not to.

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

vc

5/7/2016 7:40:00 PM

0

On Thu, 05 May 2016 10:16:58 +0100, Ben Bacarisse
<ben.usenet@bsb.me.uk> wrote:

>bit-naughty@hotmail.com writes:
><snip>
>> My question is, if I use this, as instructed:
>> insertBefore(newChild,
>> refChild) method.
>>
>> Then will the element show up right away?
>> I DON'T want it to, I want it to remain invisible till I fiddle with
>> it's CSS properties....
>
>Make sure that the initial properties render it invisible. Make it
>visible (by whatever means you are using -- the position, visibility or
>display properties) only when it is ready to be seen.

My experience is from several years ago so maybe things have changed.
IIRC updates to the document are not rendered until the current script
has finished or has suspended execution. In situations where I DID
want the document to update immediately I had to use a short
setTimeout to pause execution.

Thomas 'PointedEars' Lahn

5/7/2016 8:52:00 PM

0

Steve L <x@y.z> wrote:
^^^^^^^
Your â??Fromâ? is in violation of network standards, Netiquette, and
maybe even the Acceptable Use Policy of your service provider.
You have been warned.

> On Thu, 05 May 2016 10:16:58 +0100, Ben Bacarisse
> <ben.usenet@bsb.me.uk> wrote:

Attribution line, not attribution novel.

>>bit-naughty@hotmail.com writes:
>>Make sure that the initial properties render it invisible. Make it
>>visible (by whatever means you are using -- the position, visibility or
>>display properties) only when it is ready to be seen.
>
> My experience is from several years ago so maybe things have changed.
> IIRC updates to the document are not rendered until the current script
> has finished

Unreliable. The only reliable way to avoid additional repaint is to not
insert the element object into the document tree before its CSS properties
have been set.

> or has suspended execution.

Impossible.

> In situations where I DID want the document to update immediately I had to
> use a short setTimeout to pause execution.

Still true, except that window.setTimeout() has never paused execution (that
is a common misconception). Instead, code that is to run independent of
window updates and would potentially block execution, is to be executed with
window.setTimeout() or the Web Workers API.

--
PointedEars
FAQ: <http://PointedEars.... | SVN: <http://PointedEars.de...
Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-...
Please do not cc me. / Bitte keine Kopien per E-Mail.

Dr J R Stockton

5/8/2016 6:19:00 PM

0

In comp.lang.javascript message <2597183.QcWBBMbo8E@PointedEars.de>,
Sat, 7 May 2016 22:51:48, Thomas 'PointedEars' Lahn <PointedEars@web.de>
posted:

>> In situations where I DID want the document to update immediately I had to
>> use a short setTimeout to pause execution.
>
>Still true, except that window.setTimeout() has never paused execution (that
>is a common misconception). Instead, code that is to run independent of
>window updates and would potentially block execution, is to be executed with
>window.setTimeout() or the Web Workers API.

You are, as is customary, unnecessarily pedantic whenever that enables
you to avoid being helpful.


The setTimeout call does not of itself pause execution; but it can be
used to enable execution to restart after it stops for other reasons.
it and setInterval thereby provide /sine qua non/s for the pausing of
execution.

Pseudo-Pascal, as I am not set up to test it now :
function F() ; begin
Write(1) ;
Pause(1000) ;
Write(2)
end ;

Pseudo-JavaScript :
function F() {
Write(1)
setTimeout(G, 1000)
}

function G() :
Write(2)
;

RBTD.

--
(c) John Stockton, Surrey, UK. ¬@merlyn.demon.co.uk Turnpike v6.05 MIME.
Merlyn Web Site < > - FAQish topics, acronyms, & links.


bit-naughty

5/10/2016 7:54:00 AM

0

Sorry, I have a question:

I want to insert AFTER the only child there is, ie. say there's a LIST "Water", and I want to insert "Fire" AFTER the "Water" -then what do I do?


Thanks.