<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>By Myself &#187; js</title>
	<atom:link href="http://www.warpdesign.fr/blog/tag/js/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.warpdesign.fr/blog</link>
	<description>All by Myself</description>
	<lastBuildDate>Sat, 21 Jan 2012 00:18:25 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Un jeu en HTML 5 / JavaScript / CSS</title>
		<link>http://www.warpdesign.fr/blog/2010/07/10/un-jeu-en-html-5-javascript-css/</link>
		<comments>http://www.warpdesign.fr/blog/2010/07/10/un-jeu-en-html-5-javascript-css/#comments</comments>
		<pubDate>Sat, 10 Jul 2010 21:22:05 +0000</pubDate>
		<dc:creator>leo</dc:creator>
				<category><![CDATA[Techno]]></category>
		<category><![CDATA[Xperiments]]></category>
		<category><![CDATA[css3]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[in the mood for life]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[js]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[palm]]></category>
		<category><![CDATA[pixi]]></category>
		<category><![CDATA[pre]]></category>
		<category><![CDATA[safari]]></category>
		<category><![CDATA[transitions]]></category>
		<category><![CDATA[trip-hop]]></category>
		<category><![CDATA[triphop]]></category>
		<category><![CDATA[warpklondike]]></category>
		<category><![CDATA[wax]]></category>
		<category><![CDATA[wax tailor]]></category>
		<category><![CDATA[webkit]]></category>
		<category><![CDATA[webos]]></category>

		<guid isPermaLink="false">http://www.warpdesign.fr/blog/?p=330</guid>
		<description><![CDATA[

Intéressé par le développement sur Palm/webOS, j&#8217;ai commencé par faire un petit POC sur la possibilité de développer un petit Solitaire en HTML 5 / JavaScript. Voici quelques remarques (générales) sur le développement de jeux CSS/Html5/JavaScript.


This or That ?
La principale difficultée réside dans la variable this, qui peut prendre n&#8217;importe quelle valeur en JavaScript. Dans [...]]]></description>
			<content:encoded><![CDATA[<p>
<img src="http://www.warpdesign.fr/blog/images/warpklondike.png" alt="Espion(s)" style="float: left; margin-right: 12px;"/><br />
Intéressé par le développement sur Palm/webOS, j&#8217;ai commencé par faire un petit POC sur la possibilité de développer un petit Solitaire en HTML 5 / JavaScript. Voici quelques remarques (générales) sur le développement de jeux CSS/Html5/JavaScript.
</p>
<p><span id="more-330"></span></p>
<h1>This or That ?</h1>
<p>La principale difficultée réside dans la variable this, qui peut prendre n&#8217;importe quelle valeur en JavaScript. Dans tout autre language (Java, Cpp,&#8230;), this fera toujours référence à l&#8217;objet en cours. En JavaScript, ce n&#8217;est pas aussi simple: this dépend en fait du contexte d&#8217;appel de la méthode, ce contexte pouvant être modifié par l&#8217;utilisation de apply.</p>
<p>Comme je sens que vous commencez à tourner de l&#8217;oeil, prenons un exemple:</p>
<pre><code><span style="color: #003366; font-weight: bold;">function</span> monConstructeur<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#123;</span>
     <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">monAttribut</span> = <span style="color: #3366CC;">'yop !'</span>;
  <span style="color: #66cc66;">&#125;</span>
&nbsp;
  monConstructeur.<span style="color: #006600;">prototype</span> = <span style="color: #66cc66;">&#123;</span>
     maMethode: <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
     <span style="color: #66cc66;">&#123;</span>
        console.<span style="color: #006600;">log</span><span style="color: #66cc66;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">monAttribut</span><span style="color: #66cc66;">&#41;</span>;
     <span style="color: #66cc66;">&#125;</span>
  <span style="color: #66cc66;">&#125;</span>
  <span style="color: #003366; font-weight: bold;">var</span> monInstance = <span style="color: #003366; font-weight: bold;">new</span> monConstructeur<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
  <span style="color: #009900; font-style: italic;">// 'yop !'</span>
  monInstance.<span style="color: #006600;">maMethode</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
  <span style="color: #009900; font-style: italic;">// undefined</span>
  setTimeout<span style="color: #66cc66;">&#40;</span>monInstance.<span style="color: #006600;">maMethode</span>, <span style="color: #CC0000;">1000</span><span style="color: #66cc66;">&#41;</span>;</code></pre>
<p>A 1ère vue, les deux appels devraient tous les deux afficher &#8216;Yop !&#8217;, et pourtant, le 2ème appel affichera undefined, parce que this, dans ce cas précis, fera référence à l&#8217;objet global (ie: window), et non pas à notre instance. Mais ?! Pourquoi ?!! La valeur de this dépend en fait de l&#8217;invocation.</p>
<p>Il existe en réalité 4 patterns d&#8217;invocation de méthode en JavaScript, et la valeur de this en dépend:</p>
<p><strong>1. Le pattern d&#8217;invocation de méthode</strong></p>
<p>Dans le cas d&#8217;invocation de méthode, this fait référence à l&#8217;objet contenant la méthode:</p>
<pre><code><span style="color: #003366; font-weight: bold;">var</span> monObjet = <span style="color: #66cc66;">&#123;</span>
     monAttribut: <span style="color: #3366CC;">'yop !'</span>,
     maMethode: <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span> <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">monAttribut</span>; <span style="color: #66cc66;">&#125;</span>
  <span style="color: #66cc66;">&#125;</span>; 
&nbsp;
 <span style="color: #009900; font-style: italic;">// 'yop !'  </span>
 monObjet.<span style="color: #006600;">maMethode</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</code></pre>
<p><strong>2. Le pattern d&#8217;invocation de fonction</strong></p>
<p>Dans le cas d&#8217;une invocation de fonction, this ne devrait pas être défini, et fait pourtant référence à l&#8217;objet global. C&#8217;est une erreur de conception du language qui se verra corrigée dans la prochaine version de ECMAscript.</p>
<pre><code><span style="color: #003366; font-weight: bold;">var</span> maFonction = <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span> <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">location</span>; <span style="color: #66cc66;">&#125;</span>
  <span style="color: #009900; font-style: italic;">// Object</span>
  maFonction<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</code></pre>
<p><strong>3. Le pattern d&#8217;invocation de constructeur</strong></p>
<pre><code><span style="color: #003366; font-weight: bold;">function</span> monConstructeur<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">monAttribut</span> = <span style="color: #CC0000;">0</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> monInstance = <span style="color: #003366; font-weight: bold;">new</span> monConstructeur<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</code></pre>
<p>Lors de l&#8217;appel d&#8217;une fonction construteur préfixé par <i>new</i>, un nouvel objet est créé, avec un lien masqué vers le prototype de la fonction, et this est automatiquement lié à ce nouvel objet.</p>
<p><strong>4. Le pattern d&#8217;invocation avec apply</strong></p>
<p>La valeur de this lors de l&#8217;appel d&#8217;une fonction étant quelque peu aléatoire, il est possible de forcer la valeur de this à l&#8217;aide de apply.</p>
<pre><code><span style="color: #003366; font-weight: bold;">Function</span>.<span style="color: #006600;">apply</span><span style="color: #66cc66;">&#40;</span>valeurThis, ArrayArguments<span style="color: #66cc66;">&#41;</span>;</code></pre>
<p>Les frameworks JavaScript fournissent généralement une méthode permettant de facilement modifier la valeur de this pour l&#8217;appel d&#8217;une fonction. Il est donc facile de régler le problème précédent.</p>
<p>Par exemple, avec le framework Prototype (utilisé dans le framework MVC de Palm: Mojo), on pourrait utiliser bind:</p>
<pre><code>setTimeout<span style="color: #66cc66;">&#40;</span>monInstance.<span style="color: #006600;">maMethode</span>.<span style="color: #006600;">bind</span><span style="color: #66cc66;">&#40;</span>monInstance<span style="color: #66cc66;">&#41;</span>, <span style="color: #CC0000;">1000</span><span style="color: #66cc66;">&#41;</span>;</code></pre>
<p>Ou, en utilisant jQuery (1.4+):</p>
<pre><code>setTimeout<span style="color: #66cc66;">&#40;</span>jQuery.<span style="color: #006600;">proxy</span><span style="color: #66cc66;">&#40;</span>monInstance.<span style="color: #006600;">maMethode</span>, monInstance<span style="color: #66cc66;">&#41;</span>, <span style="color: #CC0000;">1000</span><span style="color: #66cc66;">&#41;</span>;</code></pre>
<h1>Transitions CSS</h1>
<p>Depuis la sortie de l&#8217;iPhone il y a 3 ans Apple a introduit et ne cesse de pousser les transitions CSS, beaucoup plus adaptées à la puissance limitée (tout est relatif <img src='http://www.warpdesign.fr/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> ) des smartphones. Avant l&#8217;arrivée des transitions, pour animer des objets HTML, on utilisait les frameworks tels jQuery. Par exemple, pour déplacer un objet de 100px vers la droite, on peut faire avec jQuery:</p>
<pre><code>$<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'#foo'</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">animate</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#123;</span>left: <span style="color: #3366CC;">'100px'</span><span style="color: #66cc66;">&#125;</span>, <span style="color: #CC0000;">1000</span><span style="color: #66cc66;">&#41;</span>;</code></pre>
<p>Le problème, lorsque l&#8217;on se place dans le contexte des smartphones est que tout est effectué par le processeur. La puissance de ces machines étant relativement limitée, et la batterie de courte durée, cette méthode n&#8217;est pas utilisable. Les transitions CSS (disponibles sur <strong>tous</strong> les navigateurs modernes, ce n&#8217;est pas (plus) une exclusivité webKit: Firefox, Opera, webKit) permettent de définir des animations à l&#8217;aide des CSS. Quelle est la différence me direz-vous ? La principale différence est que les animations effectuées via des transitions CSS sont accélérées graphiquement et permettent donc de libérer le processeur et, théoriquement, d&#8217;utiliser moins de batterie.</p>
<p>Les transitions étant encore en plein développement, les spécifications ne sont pas finales et chaque navigateur les implémente donc à l&#8217;aide d&#8217;un préfixe: -o- pour Opera, -moz- pour Firefox et -webkit- pour les navigateurs utilisant webkit (Safari, Chrome, OWB,&#8230;). Plusieurs manières permettent d&#8217;animer un objet à l&#8217;aide des transitions.</p>
<p><strong>1. Animation des propriétés</strong><br />
Pour un sélecteur (CSS) donné, il est possible de choisir quelle(s) propriété(s) sera/seront animée(s). Par exemple, pour animer notre bloc #foo, on utiliserait les CSS suivants:</p>
<pre><code>#foo<span style="color: #66cc66;">&#123;</span>
   -webkit-transition-property:left;
   -webkit-transition-duration:1000ms;
&nbsp;
   -o-transition-property:left;
   -o-transition-duration:1000ms;
&nbsp;
   -moz-transition-property:left;
   -moz-transition-duration:1000ms;
<span style="color: #66cc66;">&#125;</span></code></pre>
<p>La modification de la propriété left de l&#8217;objet #foo sera alors automatiquement animée, et de durée 1000ms.</p>
<p><strong>2. Animation</strong><br />
Il est aussi possible de créer des animations relativement complexes, à l&#8217;aide de keyframes, par exemple (ici pour webkit):</p>
<pre><code>@-webkit-keyframes <span style="color: #3366CC;">'zoomIn'</span> 
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #CC0000;">0</span>%<span style="color: #66cc66;">&#123;</span>
			opacity:<span style="color: #CC0000;">0</span>;
			-webkit-transform: scale<span style="color: #66cc66;">&#40;</span><span style="color: #CC0000;">1.0</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
		<span style="color: #CC0000;">25</span>%<span style="color: #66cc66;">&#123;</span>
			opacity:<span style="color: #CC0000;">1</span>;
		<span style="color: #66cc66;">&#125;</span>
		<span style="color: #CC0000;">100</span>%<span style="color: #66cc66;">&#123;</span>
			opacity:<span style="color: #CC0000;">0</span>;
			bottom:20px;
			-webkit-transform: scale<span style="color: #66cc66;">&#40;</span><span style="color: #CC0000;">3.0</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span></code></pre>
<p>Ici nous définissons une animation nommée &laquo;&nbsp;zoomIn&nbsp;&raquo;, et 3 &laquo;&nbsp;étapes&nbsp;&raquo;. Le passage à ces 3 étapes sera automatiquement animé.</p>
<p>Pour utiliser cette animation, il suffit ensuite de faire:</p>
<pre><code>#foo.<span style="color: #006600;">animate</span><span style="color: #66cc66;">&#123;</span>
   -webkit-animation: zoomIn .4s ease-<span style="color: #000066; font-weight: bold;">in</span>;
<span style="color: #66cc66;">&#125;</span></code></pre>
<p>Lorsque l&#8217;objet #foo aura la classe &#8216;animate&#8217;, il jouera automatiquement l&#8217;animation zoomIn, pendant 0.4sec, en utilisant la fonction ease-in. Cette fonction définit la vitesse de l&#8217;animation au cours du temps: ease-in étant la valeur par défaut.</p>
<p><strong>3. aller plus loin</strong><br />
Il est possible d&#8217;utiliser le JavaScript pour spécifier des fonctions callback à exécuter à la fin d&#8217;une transition. On peut ainsi définir des animations assez complexes, complexes dans tous les sens du terme: le code définir devient vraiment très complexe, et surtout on mélange maintenant simples propriétés d&#8217;affichage avec l&#8217;animation. Je conseille d&#8217;ailleurs, dès le début, de séparer les transitions CSS, des propriétés CSS classiques.</p>
<p>Et j&#8217;attends avec impatience le premier SDK permettant de développer ces animations CSS, parce que actuellement, ces transitions, aussi puissantes soient-elles sont très très difficilement accessibles, et totalement impossibles à débugger&#8230;</p>
<p>Alors: qui sera le 1er ? Adobe ? Apple ? Google ?</p>
<h1>Un WebKit, des WebKit</h1>
<p>WebKit, le moteur utilisé actuellement dans Safari (y-compris la version iPhone), Chrome, le navigateur d&#8217;Android, le futur navigateur de BlackBerry, etc&#8230; n&#8217;a pas (scoop ! <img src='http://www.warpdesign.fr/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> ) été créé par Apple mais est basé sur le projet KHTML, du groupe KDE. Ce moteur très performant a été adapté sur de nombreuses plateformes et chaque plateforme apporte ses modifications et restrictions. Ainsi, WebKit utilisé dans Safari 5 supporte des fonctionnalités non présentes dans Chrome (exemple:  <i>-webkit-backface-visibility</i>), le navigateur de Palm/webOS ne supporte pas les box-shadow ni les gradients, etc&#8230;</p>
<p>Contrairement à ce que l&#8217;on pourrait donc croire, l&#8217;utilisation de WebKit simplifie sans aucun doute le travail des développeurs des systèmes, mais en aucun cas celui des développeurs Web, puisque toutes ces différences doivent être prises en compte pour obtenir un site/une application multi-plateformes.</p>
<p>Attention donc: il existe des WebKit, pas un seul <img src='http://www.warpdesign.fr/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  Même si la base est évidemment la même, le résultat final sera probablement différent selon les plateformes.</p>
<p>- Tester et télécharger <a href="http://www.warpdesign.fr/warpklondike">WarpKlondike</a><br />
- Télécharger la version webOS pour votre <a href="http://developer.palm.com/appredirect/?packageid=com.warpdesign.warpklondike.web">Palm Pré ou Pixi</a><br />
- Plus d&#8217;informations sur les transitions: <a href="http://developer.apple.com/safari/library/documentation/internetweb/conceptual/safarivisualeffectsprogguide/Transitions/Transitions.html">Apple Developer Site</a></p>
<p><img src="http://www.warpdesign.fr/blog/images/jaquettes/leaveit.jpg" style="float:left;margin-right:14px;" alt="leave it!" /><a href="http://www.myspace.com/waxtailor" target="_blank">Wax Tailor</a> &nbsp;[ Trip-Hop ]<br />
<b>Ambiance:</b> Zen<br />
<b>Albums:</b> The train, leave it, In the mood for life<br />
<b>A écouter:</b> This Train<br />
</p>
]]></content:encoded>
			<wfw:commentRss>http://www.warpdesign.fr/blog/2010/07/10/un-jeu-en-html-5-javascript-css/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery 1.3.1: toujours mieux&#8230;</title>
		<link>http://www.warpdesign.fr/blog/2009/01/28/jquery-131-toujours-mieux/</link>
		<comments>http://www.warpdesign.fr/blog/2009/01/28/jquery-131-toujours-mieux/#comments</comments>
		<pubDate>Wed, 28 Jan 2009 16:16:12 +0000</pubDate>
		<dc:creator>leo</dc:creator>
				<category><![CDATA[Techno]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[dom]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[jquery1.3]]></category>
		<category><![CDATA[js]]></category>
		<category><![CDATA[mootools]]></category>
		<category><![CDATA[nouveautes]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[prototype]]></category>
		<category><![CDATA[selector]]></category>
		<category><![CDATA[sizzle]]></category>

		<guid isPermaLink="false">http://www.warpdesign.fr/blog/?p=203</guid>
		<description><![CDATA[jQuery est passé en version 1.3 puis rapidement en version 1.3.1. Cette version apporte le lot habituel de changements (optimisations, nouvelles fonctionnalités, réécritures, etc&#8230;) mais aussi, et surtout, casse la compatibilité avec les versions précédentes. Comme je me suis cassé les dents dessus, sans le savoir, j&#8217;ai pensé qu&#8217;il serait bon de faire un petit [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.warpdesign.fr/blog/images/jquery.png" alt="jquery" style="float: left; margin-right: 10px;"><b>jQuery</b> est passé en version 1.3 puis rapidement en version 1.3.1. Cette version apporte le lot habituel de changements (optimisations, nouvelles fonctionnalités, réécritures, etc&#8230;) mais aussi, et surtout, casse la compatibilité avec les versions précédentes. Comme je me suis cassé les dents dessus, sans le savoir, j&#8217;ai pensé qu&#8217;il serait bon de faire un <b>petit tour de quelques unes des nouveautés et incompatibilités introduites dans cette version</b>&#8230;
</p>
<p><span id="more-203"></span></p>
<p>
<b>Nouveautés</b><br />
Comme à chaque version majeure (et on peut se demander comment ils font), les développeurs de ce framework ont de nouveau augmenté les performances de jQuery:<br />
<img src="http://www.warpdesign.fr/blog/images/jquery_chart.jpg" alt="performances de jquery" style="float:left;margin:16px auto;" /></p>
<ul style="clear:left;">
<li>Réécriture de l&#8217;injection HTML: <b>6x</b> plus rapide!</li>
<li>Utilisation d&#8217;un nouveau sélecteur, <b>plus rapide:</b> <i>sizzle</i></li>
<li>Ajout des live events dans le core de jQuery</li>
<li>Nouvel objet Event</li>
<li>Réécriture de la méthode offset(), beaucoup plus rapide</li>
<li>Et bien plus&#8230;</li>
</ul>
<p><b>Incompatibilités</b><br />
Malheureusement, certaines fonctionnalités dépréciées depuis un moment ont été retirées de cette version. Les modifications à effectuer pour rendre son code compatible sont plutôt mineures, quand on sait où chercher <img src='http://www.warpdesign.fr/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
<br />
<b>1. suppression de @ dans [@attr]</b><br />
Le plus gros changement est la suppression de @. Une sélection comme:</p>
<pre>
<code>$<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'input[@name=toto]'</span><span style="color: #66cc66;">&#41;</span>...</code>
</pre>
<p>deviendra:</p>
<pre>
<code>$<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'input[name=toto]'</span><span style="color: #66cc66;">&#41;</span>...</code>
</pre>
<p>
<b>2. changements dans la méthode ready()</b><br />
Auparavant la méthode attendait le chargement de toutes les feuilles de styles. Comme ce n&#8217;est plus le cas, tous les fichiers CSS doivent être inclus avant les scripts dans la page.<br />
<br />
<b>3. Ordre des sélecteurs &laquo;&nbsp;a, b, c&nbsp;&raquo;</b><br />
L&#8217;ordre des sélecteurs peut varier. Les navigateurs supportant querySelectorAll (Safari, Firefox 3.1+, Opera 10+, IE8+) retourneront les éléments dans l&#8217;ordre du document alors que les autres navigateurs les retourneront (pour l&#8217;instant) dans l&#8217;ordre spécifié. Dans une prochaine version 1.3.x tous les sélecteurs séparés par des virgules seront retournés dans l&#8217;ordre du document.<br />
Concrètement, cela signifie que dans l&#8217;exemple suivant:<br />
<b>DOM</b></p>
<pre>
<code><span style="color: #009900;"><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">&lt;div</span></a> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;c&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	Div c
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div&gt;</span></span>
&nbsp;
  <span style="color: #009900;"><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">&lt;div</span></a> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;b&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	Div b
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div&gt;</span></span>
&nbsp;
  <span style="color: #009900;"><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">&lt;div</span></a> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;a&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	Div a
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div&gt;</span></span></code>
</pre>
<p>
<b>Code</b></p>
<pre>
<code>$<span style="color: #66cc66;">&#40;</span>document<span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">ready</span><span style="color: #66cc66;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
    $<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'#a, #b, #c'</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">each</span><span style="color: #66cc66;">&#40;</span>
      <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
         <span style="color: #000066;">alert</span><span style="color: #66cc66;">&#40;</span> $<span style="color: #66cc66;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">attr</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'id'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span>; 
      <span style="color: #66cc66;">&#125;</span>
   <span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;</code>
</pre>
<p>Les navigateurs supportant querySelectorAll (cf. au dessus), renverront les éléments dans l&#8217;ordre du DOM, à savoir:</p>
<pre>
<code>c b a</code>
</pre>
<p>Alors que les autres renverront les éléments dans l&#8217;ordre spécifié dans le sélecteur, c&#8217;est à dire:</p>
<pre>
<code>a b c</code>
</pre>
<p>Attention à ne pas se baser sur cet ordre donc !<br />
<br />
<b>Nouveautés</b><br />
Cette nouvelle version de jQuery vient comme d&#8217;habitude avec son lot de nouveautés bien pratiques, parmi lesquelles:<br />
<br />
<b>1. nouvelle méthode closest( expr )</b><br />
Cette méthode renvoie le plus proche parent correspondant à l&#8217;expression, l&#8217;élément de départ compris. Exemple:<br />
<br />
<b>DOM</b></p>
<pre>
<code><span style="color: #009900;"><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">&lt;div</span></a> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;superParent&quot;</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;main&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
     <span style="color: #009900;"><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">&lt;div&gt;</span></a></span>
        <span style="color: #009900;"><a href="http://december.com/html/4/element/ul.html"><span style="color: #000000; font-weight: bold;">&lt;ul</span></a> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;maListe&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
			<span style="color: #009900;"><a href="http://december.com/html/4/element/li.html"><span style="color: #000000; font-weight: bold;">&lt;li</span></a> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;15&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
				<span style="color: #009900;"><a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">&lt;a&gt;</span></a></span>clique !<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/a&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/li&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ul&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div&gt;</span></span></code>
</pre>
<p>
<b>Code</b></p>
<pre>
<code>$<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'a'</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">click</span><span style="color: #66cc66;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
  <span style="color: #000066;">alert</span><span style="color: #66cc66;">&#40;</span>$<span style="color: #66cc66;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">closest</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'li'</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">attr</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'id'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
  <span style="color: #000066;">alert</span><span style="color: #66cc66;">&#40;</span>$<span style="color: #66cc66;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">closest</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'div.superParent'</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">attr</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'id'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;</code>
</pre>
<p>L&#8217;exécution du code ci-dessus donnera le résultat suivant:</p>
<pre>
<code>15
main</code>
</pre>
<p>
<b>2. live events</b><br />
Auparavant, les événements n&#8217;étaient pas mis à jour en temps réel sans passer par un plugin comme <a href="http://docs.jquery.com/Plugins/livequery" target="_blank">livequery</a> et un appel comme celui là:</p>
<pre>
<code>$<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'a'</span><span style="color: #66cc66;">&#41;</span> 
    .<span style="color: #006600;">livequery</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'click'</span>, <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>event<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span> 
        <span style="color: #000066;">alert</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'clique !'</span><span style="color: #66cc66;">&#41;</span>; 
        <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span>; 
    <span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;</code>
</pre>
<p>sera tout simplement remplacé par:</p>
<pre>
<code>$<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'a'</span><span style="color: #66cc66;">&#41;</span> 
    .<span style="color: #006600;">live</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'click'</span>, <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>event<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span> 
        <span style="color: #000066;">alert</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'clique !'</span><span style="color: #66cc66;">&#41;</span>; 
        <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span>; 
    <span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;</code>
</pre>
<p><b>3. La méthode is() et selecteur not() supportent maintenant des expressions complexes, comme:</b></p>
<pre>
<code>$<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'a:not(.selected, .highlighted)'</span><span style="color: #66cc66;">&#41;</span>...</code>
</pre>
<p>
<b>Quelques liens</b><br />
Pour finir, et pour en savoir plus, voici quelques liens sur jQuery:</p>
<ul>
<li>changelog complet: <a target="_blank" href="http://docs.jquery.com/Release:jQuery_1.3" title="changelog jQuery 1.3">changelog jQuery 1.3</a></li>
<li>Introduction à <a target="_blank" href="/blog/2007/06/11/jquery/" title="Introduction à jQuery">jQuery</a></li>
<li>Documentation officielle: <a target="_blank" href="http://docs.jquery.com/" title="Documentation jQuery">docs.jquery.com</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.warpdesign.fr/blog/2009/01/28/jquery-131-toujours-mieux/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>jQuery</title>
		<link>http://www.warpdesign.fr/blog/2007/06/11/jquery/</link>
		<comments>http://www.warpdesign.fr/blog/2007/06/11/jquery/#comments</comments>
		<pubDate>Mon, 11 Jun 2007 21:50:28 +0000</pubDate>
		<dc:creator>leo</dc:creator>
				<category><![CDATA[Techno]]></category>
		<category><![CDATA[dom]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[js]]></category>
		<category><![CDATA[motools]]></category>

		<guid isPermaLink="false">http://www.warpdesign.fr/blog/?p=26</guid>
		<description><![CDATA[
Si vous êtes un petit au courant des dernières technologies du web, vous avez sans doute entendu parlé d&#8217;Ajax. Tout le monde en a fait tout un foin, mais Ajax existe depuis bien longtemps et a été pour la première fois introduit par un certain Internet Explorer (ça alors!  ). Et depuis, chaque navigateur [...]]]></description>
			<content:encoded><![CDATA[<p>
Si vous êtes un petit au courant des dernières technologies du web, vous avez sans doute entendu parlé d&#8217;Ajax. Tout le monde en a fait tout un foin, mais Ajax existe depuis bien longtemps et a été pour la première fois introduit par un certain Internet Explorer (ça alors! <img src='http://www.warpdesign.fr/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> ). Et depuis, chaque navigateur a plus ou moins imposé sa propre API. Donc pour nous développeurs, c&#8217;est la galère!<br />
<br />
<b>Mais heureusement jQuery est né!</b></p>
<p><span id="more-26"></span><br />
Si vous êtes ici c&#8217;est que vous ne connaissez pas jQuery et que vous voulez en savoir plus&#8230; Alors fini le blabla <img src='http://www.warpdesign.fr/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
Non, jQuery n&#8217;est pas un nouvel applet Java, mais bel et bien un framework Javascript qui permet, entre autres de simplifier l&#8217;utilisation de l&#8217;ajax, mais aussi de manipuler le DOM de votre document, et tout ceci, très, très simplement!<br />
Comme un exemple vaut souvent mieux qu&#8217;un long discours, et que de toutes façons je suis mauvais pour les discours, je vais vous démontrer sa simplicité et sa puissance en quelques exemples&#8230;<br />
<br />
Commençons par l&#8217;exemple le plus simple. Admettons que notre document contienne un élément d&#8217;id &laquo;&nbsp;truc&nbsp;&raquo;, et que nous souhaitions injecter une chaîne de caractères &laquo;&nbsp;bonjour !&nbsp;&raquo; à l&#8217;intérieur:</p>
<pre><code>$<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;#truc&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">html</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;bonjour !&quot;</span><span style="color: #66cc66;">&#41;</span>;</code></pre>
<p><b>Au niveau du DOM, avant:</b></p>
<pre><code><span style="color: #009900;"><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">&lt;p</span></a> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;truc&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/p&gt;</span></span></code></pre>
<p><b>&#8230;Après:</b></p>
<pre><code><span style="color: #009900;"><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">&lt;p</span></a> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;truc&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>bonjour !<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/p&gt;</span></span></code></pre>
<p>Alors, deux choses. L&#8217;accesseur &laquo;&nbsp;$&nbsp;&raquo; permet d&#8217;accéder à un objet jQuery. Ici, d&#8217;identifiant &laquo;&nbsp;truc&nbsp;&raquo;. $(&nbsp;&raquo;#truc&nbsp;&raquo;) nous renvoie donc un objet (au sens javascript, mais aussi jQuery) qui possède de nombreuses méthodes. La méthode html() permet de modifier le contenu innerHTML de l&#8217;objet avec le contenu passé en paramètre. Simple, non ? Maintenant admettons que nous souhaitions modifier la classe utilisée par cet élément. Rien de plus simple en jQuery:</p>
<pre><code>$<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;#truc&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">addClass</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;ma_classe&quot;</span><span style="color: #66cc66;">&#41;</span>;</code></pre>
<p><b>Au niveau du DOM, avant:</b></p>
<pre><code><span style="color: #009900;"><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">&lt;p</span></a> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;truc&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>bonjour !<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/p&gt;</span></span></code></pre>
<p><b>&#8230;Après:</b></p>
<pre><code><span style="color: #009900;"><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">&lt;p</span></a> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;truc&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;ma_classe&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>bonjour !<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/p&gt;</span></span></code></pre>
<p>Comme vous pouvez le voir notre paragraphe possède maintenant la classe &laquo;&nbsp;ma_classe&nbsp;&raquo;. Simple, non ? Maintenant voyons un peu comment fonctionne l&#8217;Ajax&#8230; Admettons que nous ayons un script &laquo;&nbsp;heure.php&nbsp;&raquo; qui nous renvoie l&#8217;heure, sous forme de chaîne de caractères&#8230; Et que nous souhaitions modifier le contenu de notre paragraphe d&#8217;id &laquo;&nbsp;truc&nbsp;&raquo; avec le résultat de l&#8217;appel Ajax de ce script&#8230; Rien de plus simple avec jQuery:</p>
<pre><code><span style="color: #003366; font-weight: bold;">function</span> set_time<span style="color: #66cc66;">&#40;</span>msg<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
    $<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;#truc&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">html</span><span style="color: #66cc66;">&#40;</span>msg<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
$.<span style="color: #006600;">post</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;http://mon_site/heure.php&quot;</span>, set_time<span style="color: #66cc66;">&#41;</span>;</code></pre>
<p><b>Au niveau du DOM, avant:</b></p>
<pre><code><span style="color: #009900;"><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">&lt;p</span></a> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;truc&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/p&gt;</span></span></code></pre>
<p><b>&#8230;Après:</b></p>
<pre><code><span style="color: #009900;"><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">&lt;p</span></a> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;truc&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Mardi 12 Juin - 18:36:45<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/p&gt;</span></span></code></pre>
<p>Alors, qu&#8217;est-ce que l&#8217;on voit ici ? Nous définissons tout d&#8217;abord une fonction javascript set_time() qui prend en paramètre un message msg. C&#8217;est en fait la fonction <i>callback</i> qui sera appelée lorsque la requête AJax aura été effectuée. Le paramètre contiendra le message renvoyé par le serveur. Cette fonction, modifie le contenu <i>innerHTML</i> du paragraphe d&#8217;id &laquo;&nbsp;truc&nbsp;&raquo;, comme nous l&#8217;avons vu précédemment: jusque là rien de nouveau. La ligne suivante fait appel à une méthode de jQuery (d&#8217;où le $.), &laquo;&nbsp;post&nbsp;&raquo; qui effectue une requête asynchrone vers le serveur http://mon_site sur le script heure.php. Lorsque le serveur renvoie son résultat, la fonction set_time() est automatiquement appelée avec en paramètre le résultat de la requête Ajax.<br />
Ici on a choisit de passer le nom d&#8217;une fonction javascript comme second paramètre de la méthode post(), mais il tout à fait possible de définir la fonction de manière <i>inline</i>:</p>
<pre><code>$.<span style="color: #006600;">post</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;http://mon_site/heure.php&quot;</span>, <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span>msg<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
    $<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;#truc&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">html</span><span style="color: #66cc66;">&#40;</span>msg<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;</code></pre>
<p>
<b>Note:</b> le code devient vite illisible et difficile à maintenir lorsque l&#8217;on abuse d&#8217;appels inline!<br />
<br />
<b>Les évènements</b><br />
Vous avez sans doute déjà <i>bindé</i> (lié) un évènement (par exemple <i>onClick</i>) à une fonction en javascript, par exemple avec la fonction onClick().<br />
Cette méthode permettant de lier un évènement à un objet a plusieurs inconvénients. Le premier est que le code se retrouve mélangé avec le HTML. Le deuxième est que le code est statique: il est définit une bonne fois pour toutes lors de la création/génération de la page.<br />
Et bien avec jQuery, ces deux inconvénients disparaissent puisqu&#8217;il est maintenant possible de <i>binder</i> n&#8217;importe quel évènement Javascript à n&#8217;importe quel élément de notre DOM. Ainsi, en reprenant l&#8217;exemple précédent, et en rajoutant un bouton nous obtenons le code suivant:</p>
<pre><code><span style="color: #003366; font-weight: bold;">function</span> set_time<span style="color: #66cc66;">&#40;</span>msg<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
    $<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;#truc&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">html</span><span style="color: #66cc66;">&#40;</span>msg<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> envoi_requete<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
    $.<span style="color: #006600;">post</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;http://mon_site/heure.php&quot;</span>, set_time<span style="color: #66cc66;">&#41;</span>; 
<span style="color: #66cc66;">&#125;</span>
&nbsp;
$<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;#mon_bouton&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">click</span><span style="color: #66cc66;">&#40;</span> envoi_requete <span style="color: #66cc66;">&#41;</span>;</code></pre>
<p>Aussi simplement que l&#8217;on modifie le contenu <i>innerHTML</i> d&#8217;un objet avec la méthode html(), il est possible de binder un évènement à <b>n&#8217;importe quel</b> objet ! La méthode click() permet de binder, comme vous l&#8217;aurez deviné, l&#8217;évènement &laquo;&nbsp;clique&nbsp;&raquo; de la souris à n&#8217;importe quel objet. Le code précédent va donc appeler la fonction envoi_requete() dès que l&#8217;utilisateur cliquera sur le bouton d&#8217;id &laquo;&nbsp;mon_bouton&nbsp;&raquo;. Cette fonction déclenchera la requête Ajax. Une fois cette requête terminée, le résultat sera injecté dans le innerHTML de l&#8217;objet d&#8217;id &laquo;&nbsp;truc&nbsp;&raquo;. A noter qu&#8217;encore une fois, il est ici tout à fait possible de définir de manière <i>inline</i> la fonction appelée lorsque l&#8217;évènement clique est détecté.<br />
<br />
<b>Pour finir&#8230;</b><br />
Cette petite introduction à jQuery touche à sa fin. Non pas que je n&#8217;ai plus rien à dire: je pourrai parler des possibilités offertes par cette librairie pendant des heures, mais il commence à se faire tard, et le but de cet article était seulement de donner un petit aperçu de cette librairie et des différents domaines qu&#8217;elle touche. Avant de finir je vais cependant introduire une dernière fonction très utile et importante, la méthode</p>
<pre><code>$<span style="color: #66cc66;">&#40;</span>document<span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">ready</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span></code></pre>
<p>Elle est appelée une fois le DOM de la page complètement chargé. Lorsque vous utilisez jQuery, il est <b>obligatoire</b> de binder vos différents évènements dans cette fonction, de manière à être sûr que tout fonctionne correctement:</p>
<pre><code>$<span style="color: #66cc66;">&#40;</span>document<span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">ready</span><span style="color: #66cc66;">&#40;</span>
<span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
   <span style="color: #000066;">alert</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'Le DOM est prêt :)'</span><span style="color: #66cc66;">&#41;</span>; 
<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;</code></pre>
<p>
<b>Quelques liens</b></p>
<ul>
<li><a href="http://www.jquery.com">jQuery.com</a>: Site Officiel</li>
<li><a href="http://http://www.visualjquery.com">VisualjQuery</a>: Documentation très bien faite (malheureusement plus mise à jour depuis longtemps)</li>
</ul>
<p>
Ah, et j&#8217;oubliais: merci à lolo de m&#8217;avoir fait découvrir cette petite perle <img src='http://www.warpdesign.fr/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
<br />
Et j&#8217;oubliais aussi: rien à voir avec jQuery, mais voilà le petit extrait musical du moment&#8230;<b>Until the Morning &#8211; Thievery Corporation</b></p>
<div align="center"></div></p>
]]></content:encoded>
			<wfw:commentRss>http://www.warpdesign.fr/blog/2007/06/11/jquery/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

