J3.x talk

Adding JavaScript and CSS to the page

From Joomla! Documentation

Replace the example script[edit]

The script ist written with mootools and should be replaced with a version in JQuery


Hello there.. I was about to pitch in and add on a whole other section on basically doing the exact same thing you did with $document.. except using the JHTML class. I wasn't exactly sure why you'd use one over the other and thought I'd ask if you knew why this redunacy exists and if one is in some way more helpful. Any ideas? Haelix 23:45, 8 November 2008 (EST)

Haelix, I agree. It appears that the JHTML classes wrap the $document methods, and take care of anything else you might need (like mootools). I have updated the article to reflect this.Mike 21:24, 17 February 2009 (UTC)

what page should we keep ? this one http://docs.joomla.org/Adding_JavaScript or this one http://docs.joomla.org/Adding_JavaScript_and_CSS_to_the_page ?


Using the class loader method is the common way:

JHTML::_('script', $filename, $path);
JHTML::_('stylesheet', $filename, $path);

Bembelimen


A comment on xhtml validity & well-formedness[edit]

A few pointers on the current start of the article:

-well-formedness refers to balancing tags and nesting elements correctly, making it valid XML

-validity, i.e. conforming to (one of) the XHTML DTD(s), is what you are talking about with style- and script-elements and where they are allowed. Further, script-elements _are_ allowed inside the document's body-element, whether as external files with the src-attribute or inline inside script-tags. Style-elements on the other hand are only allowed inside the head-element, as you write.