You probably shouldn't use document.write() for anything; Dynamic HTML 
and the DOM have pretty much

made is obsolete.

document.write() will replace the whole document if you run it at any 
time except when the document is being loaded.

So you can use it inline:

<span class="y"><script>

        var today=new Date();

        document.write(today.getFullYear());

    </script></span>

And it gets executed when the document is loaded.

But $(..).ready(...) gets executed only after the document has been 
loaded and the DOM has been created, so

calling document.write() will replace the whole document with a new one.



Kristaps Ancāns wrote:

> Ok i'm a newbie in jquery and i'm trying to write function that will 
> replace all <span class="y"><!-- --></span> element's content with 
> current year.
>  
> My function looks like this:
>  
> $(function(){
>  $(".y").ready(function() {
>   var today = new Date();
>   var year = today.getFullYear();
>   document.write(year);
>  });
> });
> but when i run it - it replaces all the document with current year. In 
> which place my mistake is ?
> -- 
> FYFI - for your fucking information
> ------------------------------------------------------------------------
>
> _______________________________________________
> jQuery mailing list
> discuss@jquery.com
> http://jquery.com/discuss/
>   


_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/

Reply via email to