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


Groups > it.comp.lang.javascript > #8262

Re: jquery 3 e document.ready

X-Received by 2002:a24:75c9:: with SMTP id y192-v6mr2188459itc.13.1539792139715; Wed, 17 Oct 2018 09:02:19 -0700 (PDT)
X-Received by 2002:a9d:528e:: with SMTP id f14mr474846oth.4.1539792139419; Wed, 17 Oct 2018 09:02:19 -0700 (PDT)
Path csiph.com!weretis.net!feeder6.news.weretis.net!feeder.usenetexpress.com!feeder-in1.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!x98-v6no66428ita.0!news-out.google.com!n199-v6ni135itn.0!nntp.google.com!z5-v6no66119ite.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
Newsgroups it.comp.lang.javascript
Date Wed, 17 Oct 2018 09:02:19 -0700 (PDT)
In-Reply-To <1cd4f41d-cca6-4adf-8b2f-671486214f29@googlegroups.com>
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=2a02:ed8:1001:0:921b:eff:fe57:f80; posting-account=cuukCAoAAADppFjm3lellRzd6p__ft4I
NNTP-Posting-Host 2a02:ed8:1001:0:921b:eff:fe57:f80
References <1cd4f41d-cca6-4adf-8b2f-671486214f29@googlegroups.com>
User-Agent G2/1.0
MIME-Version 1.0
Message-ID <b495a545-ae50-40d0-91b6-10e7b3f4c3f8@googlegroups.com> (permalink)
Subject Re: jquery 3 e document.ready
From gandalf.corvotempesta@gmail.com
Injection-Date Wed, 17 Oct 2018 16:02:19 +0000
Content-Type text/plain; charset="UTF-8"
Content-Transfer-Encoding quoted-printable
Lines 39
Xref csiph.com it.comp.lang.javascript:8262

Show key headers only | View raw


Come se non bastasse, ho questo assurdo comportamento:

-------------------------------------------------------
var funzione = function() {
   // varie cose che richiedono il DOM inizializzato
}


$.ready.then(function(){
   // bla bla bla

   funzione(); // questa muore
});
-------------------------------------------------------


Muore, perchè quando chiamo "funzione()" il DOM non è inizializzato
di conseguenza da li dentro non posso manipolare gli elementi.

Assurdo, non ha senso, il richiamo della funzione avviene *dentro* la
document ready, quindi per forza di cose anche dentro la funzione il
dom è presente.

E' come se la $.ready.then(function(){}) in realtà non triggerasse
al ready del dom, ma questo è il metodo ufficiale da usare con jquery >= 3

Ho provato anche con $(document).ready(function() {}); o $(function() {})
ma non cambia assolutamente nulla.

Analogia: se richiamo un evento di google maps (e google maps io lo
inizializzo dentro una document ready, pertanto l'evento non si può
verificare senza aver prima inizializzato il dom), si spacca il mondo
perchè anche in questo caso, all'esecuzione dell'evento il dom non è pronto.

Il workaround è stato mettere tutto il codice chiamato nei vari eventi, evento
per evento, singolarmnente dentro la $.ready.then(function(){});

Back to it.comp.lang.javascript | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

jquery 3 e document.ready gandalf.corvotempesta@gmail.com - 2018-10-16 04:07 -0700
  Re: jquery 3 e document.ready gandalf.corvotempesta@gmail.com - 2018-10-17 09:02 -0700
  Re: jquery 3 e document.ready Alessandro Pellizzari <shuriken@amiran.it> - 2018-10-19 10:12 +0100
    Re: jquery 3 e document.ready gandalf.corvotempesta@gmail.com - 2018-10-19 03:22 -0700

csiph-web