On Apr 12, 10:41 am, Klaus Hartl <[EMAIL PROTECTED]> wrote:
> wyo schrieb:
>
> > As I understand $(document).ready() is more or less just an enclosure
> > to make sure the DOM is correcly available for use with jQuery. As it
>
> Yes, the goal should be to separate behavior (JavaScript) and structure
> (HTML), just like you (hopefully) already do with presentation (CSS) and
> structure.
>
I try albeit I admit not always, separation isn't always good and I
want to be able to decide when to separate or not.

> That said you should avoid inline event handlers ("on" HTML attributes)
> and attach these handlers from an (external) script. These "on"
> attributes are the equivalent to font tags and other presentational
> attributes in HTML.
>
Ok.

> spread over 97 templates that gives you the maintenance hell if you need
> to change the width of the popup or remove the popup.
>
True, yet I happen to have just 1 reference most of the time. But I
understand it's better in case of multiple references.

> > What happens if I still use e.g. onclick somewhere in the page
> > possibly when this event is already bound to a function in the
> > enclosure? Should this be avoided? What are the implications?
>
> I'm not sure. I think both handlers will be fired.
>
Maybe a seldom case but I'd appreciate if it was clarified in the API.

> If you include external scripts in the head, the DOM is not ready,
> because at that point it is simply not loaded. You could circumvent this
>
Well IMO the time when an event is fired is important. Besides isn't
the DOM ready when the Onload is fired?

> > $(function() is mentioned as a shorthand for $(document).ready(), does
> > this mean I could use whatever syntax I like more?
>
> Yes. The shorthand is less to type, which is convenient but less
> readable in my opinion.
>
Ok, I'll stick to .ready().

> (function($) {
>
>      // use $ here safely
>
> })(jQuery);
>
I probably won't start writing plugins right away ;-)

O. Wyss

Reply via email to