<?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>andreas-schlapsi.at &#187; AJAX</title>
	<atom:link href="http://www.andreas-schlapsi.at/tag/ajax/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.andreas-schlapsi.at</link>
	<description>Software-Entwicklung, .NET &#38; Co.</description>
	<lastBuildDate>Sat, 17 Sep 2011 16:28:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>jQuery: Effektvoll ein- und ausblenden</title>
		<link>http://www.andreas-schlapsi.at/2008/11/09/jquery-effektvoll-ein-und-ausblenden/</link>
		<comments>http://www.andreas-schlapsi.at/2008/11/09/jquery-effektvoll-ein-und-ausblenden/#comments</comments>
		<pubDate>Sun, 09 Nov 2008 21:49:11 +0000</pubDate>
		<dc:creator>Andreas Schlapsi</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[JavaScript & HTML]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.andreas-schlapsi.at/?p=238</guid>
		<description><![CDATA[Nachdem ich in dieser Serie beschrieben habe, wie Sie mit jQuery DOM-Elemente auswählen und den Dokumentenbaum verändern können, geht es dieses Mal darum, wie Sie mit jQuery DOM-Elemente effektvoll ein- und ausblenden können. Elemente ein- und ausblenden Um Elemente ein- bzw. auszublenden, kennt jQuery drei Methoden: show &#8211; macht alle selektierten Elemente sichtbar, falls sie [...]]]></description>
			<content:encoded><![CDATA[<p>Nachdem ich in dieser Serie beschrieben habe, wie Sie mit jQuery <a href="http://www.andreas-schlapsi.at/2008/10/10/jquery-dom-elemente-auswahlen/">DOM-Elemente auswählen</a> und den <a href="http://www.andreas-schlapsi.at/2008/10/30/jquery-den-dokumentenbaum-manipulieren/">Dokumentenbaum verändern</a> können, geht es dieses Mal darum, wie Sie mit jQuery DOM-Elemente effektvoll ein- und ausblenden können.</p>
<h3>Elemente ein- und ausblenden</h3>
<p>Um Elemente ein- bzw. auszublenden, kennt jQuery drei Methoden:</p>
<ul>
<li><strong>show</strong> &#8211; macht alle selektierten Elemente sichtbar, falls sie nicht sichtbar sind.</li>
<li><strong>hide</strong> &#8211; macht alle selektierten Elemente unsichtbar, falls sie sichtbar sind.</li>
<li><strong>toggle</strong> &#8211; macht alle nicht sichtbaren selektierten Elemente sichtbar und alle sichtbaren selektierten Elemente unsichtbar.</li>
</ul>
<p><span id="more-238"></span></p>
<h3>Die Geschwindigkeit eines Effekts angeben</h3>
<p>Die Geschwindigkeit, mit der jQuery einen Effekt ausführt, kann mit dem Parameter <strong>speed</strong> angegeben werden. jQuery interpretiert einen numerischen Wert als die Dauer der Animation in Millisekunden. Als Strings sind die vordefinierten Werte &#8220;slow&#8221;, &#8220;normal&#8221; und &#8220;fast&#8221; gültig. In jQuery&nbsp;1.2.6 sind diese Werte mit 600&nbsp;ms, 400&nbsp;ms und 200&nbsp;ms definiert.</p>
<p>Die meisten Effektmethoden von jQuery haben einen weiteren optionalen Parameter: <strong>callback</strong>. Damit kann eine Funktion übergeben werden, die nach Abschluss der Animation aufgerufen wird.</p>
<p><a href="http://www.andreas-schlapsi.at/wp-content/uploads/2008/11/jquery_04-2_callback.html" target="_blank">Ein Beispiel</a> zeigt die Methoden show und hide mit verschiedenen Geschwindigkeiten.</p>
<p>Der HTML-Code dieses Beispiels:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #00bbdd;">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; </span>
<span style="color: #00bbdd;">    &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;html<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;head<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>jQuery 04 - Show und Hide<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;script</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;jquery.js&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;script</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;jquery_04-1_show_hide.js&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;style</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/css&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      div { width: 100px; height: 100px; background-color: yellow; border: 1px solid #000; }
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/style<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/head<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;input</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;hideButton&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;button&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;hide&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;input</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;showButton&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;button&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;show&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;div1&quot;</span> <span style="color: #000066;">style</span>=<span style="color: #ff0000;">&quot;position: absolute; left: 10px; top: 60px&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>speed: &quot;slow&quot;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;div2&quot;</span> <span style="color: #000066;">style</span>=<span style="color: #ff0000;">&quot;position: absolute; left: 160px; top: 60px&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>speed: &quot;normal&quot;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;div3&quot;</span> <span style="color: #000066;">style</span>=<span style="color: #ff0000;">&quot;position: absolute; left: 310px; top: 60px&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>speed: &quot;fast&quot;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;div4&quot;</span> <span style="color: #000066;">style</span>=<span style="color: #ff0000;">&quot;position: absolute; left: 10px; top: 210px&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>speed: 600<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;div5&quot;</span> <span style="color: #000066;">style</span>=<span style="color: #ff0000;">&quot;position: absolute; left: 160px; top: 210px&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>speed: 400<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;div6&quot;</span> <span style="color: #000066;">style</span>=<span style="color: #ff0000;">&quot;position: absolute; left: 310px; top: 210px&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>speed: 200<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/html<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>Und hier ist der JavaScript-Code:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#hideButton&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#div1&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;slow&quot;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#div2&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;normal&quot;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#div3&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;fast&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#div4&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">600</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#div5&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">400</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#div6&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">200</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#showButton&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#div1&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;slow&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#div2&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;normal&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#div3&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;fast&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#div4&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">600</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#div5&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">400</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#div6&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">200</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h3>Fade-In und Fade-Out</h3>
<p>Um Elemente mit Fade-In und Fade-Out ein- und auszublenden, kennt jQuery die Methoden fadeIn und fadeOut. Verwendet werden sie wie show und hide, wie im <a href="http://www.andreas-schlapsi.at/wp-content/uploads/2008/11/jquery_04-3_fade.html" target="_blank">folgenden Beispiel</a> zu sehen ist:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#hideButton&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#div1&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">fadeOut</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;slow&quot;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#div2&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">fadeOut</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;normal&quot;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#div3&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">fadeOut</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;fast&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#div4&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">fadeOut</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">600</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#div5&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">fadeOut</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">400</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#div6&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">fadeOut</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">200</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#showButton&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#div1&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">fadeIn</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;slow&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#div2&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">fadeIn</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;normal&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#div3&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">fadeIn</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;fast&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#div4&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">fadeIn</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">600</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#div5&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">fadeIn</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">400</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#div6&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">fadeIn</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">200</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Eine weitere interessante Methode ist <strong>fadeTo</strong>, bei der der Zielwert für die Transparenz mit dem Parameter <strong>opacity</strong> angegeben werden kann. Mehr Informationen gibt&#8217;s in der <a href="http://docs.jquery.com/Effects/fadeTo#speedopacitycallback">jQuery-Dokumentation</a>.</p>
<h3>Slide-Effekt</h3>
<p>Die zwei Methoden <strong>slideDown</strong> und <strong>slideUp</strong> funktionieren wie die bisher beschriebenen Methoden, wie <a href="http://www.andreas-schlapsi.at/wp-content/uploads/2008/11/jquery_04-4_slide.html" target="_blank">folgendes Beispiel</a> zeigt:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#hideButton&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#div1&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">slideUp</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;slow&quot;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#div2&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">slideUp</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;normal&quot;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#div3&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">slideUp</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;fast&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#div4&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">slideUp</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">600</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#div5&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">slideUp</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">400</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#div6&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">slideUp</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">200</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#showButton&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#div1&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">slideDown</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;slow&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#div2&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">slideDown</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;normal&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#div3&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">slideDown</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;fast&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#div4&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">slideDown</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">600</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#div5&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">slideDown</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">400</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#div6&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">slideDown</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">200</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Die Methode <strong>slideToggle</strong> funktioniert so wie slideDown und slideUp abhängig davon, ob das Zielelement sichtbar ist oder nicht. Mehr Informationen gibt es wieder in der <a href="http://docs.jquery.com/Effects/slideToggle#speedcallback">jQuery-Dokumentation</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andreas-schlapsi.at/2008/11/09/jquery-effektvoll-ein-und-ausblenden/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>jQuery: Den Dokumentenbaum manipulieren</title>
		<link>http://www.andreas-schlapsi.at/2008/10/30/jquery-den-dokumentenbaum-manipulieren/</link>
		<comments>http://www.andreas-schlapsi.at/2008/10/30/jquery-den-dokumentenbaum-manipulieren/#comments</comments>
		<pubDate>Thu, 30 Oct 2008 06:22:21 +0000</pubDate>
		<dc:creator>Andreas Schlapsi</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[JavaScript & HTML]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.andreas-schlapsi.at/?p=111</guid>
		<description><![CDATA[Letztes Mal ging&#8217;s darum, wie man DOM-Elemente in jQuery auswählen kann. Dieses Mal werfen wir einen Blick darauf, wie man den Dokumentenbaum ändern kann. In den letzten Folgen haben wir bereits einige Methoden kennengelernt: text &#8211; ändert den Textinhalt eines Elements. toggle &#8211; macht ein Element sichtbar, wenn es zuvor unsichtbar war, und umgekehrt. Inhalte [...]]]></description>
			<content:encoded><![CDATA[<p>
<a href="http://www.andreas-schlapsi.at/2008/10/10/jquery-dom-elemente-auswahlen/">Letztes Mal</a> ging&#8217;s darum, wie man DOM-Elemente in jQuery auswählen kann. Dieses Mal werfen wir einen Blick darauf, wie man den Dokumentenbaum ändern kann.
</p>
<p>
In den letzten Folgen haben wir bereits einige Methoden kennengelernt:</p>
<ul>
<li><strong><code>text</code></strong> &#8211; ändert den Textinhalt eines Elements.</li>
<li><strong><code>toggle</code></strong> &#8211; macht ein Element sichtbar, wenn es zuvor unsichtbar war, und umgekehrt.</li>
</ul>
<p><span id="more-111"></span></p>
<h3>Inhalte einfügen</h3>
<p>Die Methoden zur Änderung der Inhalte (<code>html</code> und <code>text</code>) haben wir bereits in den letzten Folgen kennengelernt. Viel mehr Methoden gibt es, um neue Inhalte in den Dokumentenbaum einzufügen. In der jQuery-Dokumentation findet man <a href="http://docs.jquery.com/Manipulation">Details über die Methoden zur Manipulation des Dokumentbaumes</a>.</p>
<p><a href="http://www.andreas-schlapsi.at/wp-content/uploads/2008/10/jquery_03_appendto.html" target="_blank">Dieses Beispiel</a> (in neuem Fenster) demonstriert das Kopieren von Elementen von einem Quell- in einen Zielbereich. Der JavaScript-Code dafür sieht so aus:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#changeButton&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.target&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.source&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">appendTo</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.target&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Die Methode <code>empty</code> löscht alle Kindelemente der ausgewählten Elemente. In unserem Fall sind das alle Elemente, die mit der CSS-Klasse &#8220;target&#8221; ausgezeichnet wurden. In Zeile 4 wird der Inhalt aller Elemente mit der CSS-Klasse &#8220;source&#8221; verkettet und in alle Elemente mit der CSS-Klasse &#8220;target&#8221; eingefügt.</p>
<h3>Subelemente ersetzen</h3>
<p>Im <a href="http://www.andreas-schlapsi.at/wp-content/uploads/2008/10/jquery_04_replacewith.html" target="_blank">nächsten Beispiel</a> (in neuem Fenster) wird der Button durch ein DIV-Element ausgetauscht. Der JavaScript-Code sieht folgendermaßen aus:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#replacingButton&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">replaceWith</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;&lt;div&gt;Hello, world!&lt;/div&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h3>Subelemente löschen</h3>
<p>Weiter oben hatten wir bereits ein Beispiel, in dem mit <code>empty()</code> alle Subelemente gelöscht wurden. Mit der Methode <code>remove</code> werden alle selektierten Elemente aus dem Dokumentenbaum entfernt. Die Objekte bleiben erhalten und selektiert, d.h. man kann die entfernten Elemente noch in verketteten Methodenaufrufen verwenden. Im obigen Beispiel haben wir Elemente kopiert. Ich habe das <a href="http://www.andreas-schlapsi.at/wp-content/uploads/2008/10/jquery_05_remove.html" target="_blank">Beispiel ein wenig modifiziert</a>, um die Elemente nicht nur zu kopieren, sondern zu verschieben:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#changeButton&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.target&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.source&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">remove</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">appendTo</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.target&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h3>Elemente klonen</h3>
<p>Die Methode <code>clone()</code> erstellt einen Klon der ausgewählten Elemente und selektiert die Klons für weitere Methodenaufrufe. Ein optionaler Parameter vom Typ <code>bool</code> gibt an, ob Eventhandler ebenfalls geklont werden sollen. Der voreingestellte Wert ist <code>false</code>.</p>
<p>Ich habe <a href="http://www.andreas-schlapsi.at/wp-content/uploads/2008/10/jquery_06_clone.html" target="_blank">das obige Beispiel ein weiteres Mal modifiziert</a> (in neuem Fenster):</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#changeButton&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.source&quot;</span><span style="color: #009900;">&#41;</span>
        .<span style="color: #660066;">clone</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;source&quot;</span><span style="color: #009900;">&#41;</span>
	.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;target&quot;</span><span style="color: #009900;">&#41;</span>
	.<span style="color: #660066;">appendTo</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;body&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Zuerst werden alle Elemente mit der CSS-Klasse &#8220;source&#8221; selektiert und geklont. Der Wert des Attributs <code>class</code> aller Klone wird so modifiziert, dass die Klasse &#8220;source&#8221; nicht mehr vorhanden ist (Methode <code>removeClass()</code>) und die Klasse &#8220;target&#8221; hinzugefügt wird (Methode <code>addClass()</code>). Die Methode <code>appendTo</code> fügt dann die Klone in das <code>body</code>-Element ein.</p>
<p>Mehr Details zu den Methoden <code>addClass()</code> und <code>removeClass()</code> gibt&#8217;s in der <a href="http://docs.jquery.com/Attributes">jQuery-Dokumentation</a>.</p>
<h3>Weitere Methoden</h3>
<p>jQuery kennt natürlich noch mehr Methoden, die den Dokumentenbaum manipulieren. Die <a href="http://docs.jquery.com/Main_Page">jQuery-Dokumentation</a> <a href="http://docs.jquery.com/Manipulation">enthält Details dazu</a>.</p>
<h3>Zusammenfassung</h3>
<p>jQuery bietet jede Menge Methoden an, um den Dokumentenbaum zu manipulieren. Inhalte können geändert, eingefügt, gelöscht, ersetzt und kopiert werden.</p>
<p>In der nächsten Folge werde ich mich mit den in jQuery eingebauten Effekten beschäftigen.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andreas-schlapsi.at/2008/10/30/jquery-den-dokumentenbaum-manipulieren/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Intellisense für jQuery in Visual Studio 2008</title>
		<link>http://www.andreas-schlapsi.at/2008/10/27/intellisense-fur-jquery-in-visual-studio-2008/</link>
		<comments>http://www.andreas-schlapsi.at/2008/10/27/intellisense-fur-jquery-in-visual-studio-2008/#comments</comments>
		<pubDate>Mon, 27 Oct 2008 21:32:35 +0000</pubDate>
		<dc:creator>Andreas Schlapsi</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[JavaScript & HTML]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.andreas-schlapsi.at/?p=145</guid>
		<description><![CDATA[Bertrand Le Roy hat heute bekanntgegeben, dass die Intellisense-Dokumentationsdateien für jQuery in Visual Studio 2008 von der jQuery-Homepage heruntergeladen werden kann. Tatsächlich gibt es einen Download-Link, der als Dokumentationsdatei für Visual Studio bezeichnet wird. In der Datei jquery-1.2.6-vsdoc.js befindet sich der jQuery-Quellcode mit XML-Kommentaren. Sie sollten diese jQuery-Variante nur zum Entwickeln verwenden. Bertrand Le Roy [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://weblogs.asp.net/bleroy/">Bertrand Le Roy</a> hat heute <a href="http://weblogs.asp.net/bleroy/archive/2008/10/27/jquery-intellisense-documentation-file-available.aspx">bekanntgegeben</a>, dass die Intellisense-Dokumentationsdateien für jQuery in Visual Studio 2008 von der <a href="http://docs.jquery.com/Downloading_jQuery">jQuery-Homepage heruntergeladen werden kann</a>. Tatsächlich gibt es einen Download-Link, der als Dokumentationsdatei für Visual Studio bezeichnet wird.</p>
<p>In der Datei <code>jquery-1.2.6-vsdoc.js</code> befindet sich der jQuery-Quellcode mit XML-Kommentaren. Sie sollten diese jQuery-Variante nur zum Entwickeln verwenden. Bertrand Le Roy schlägt vor, die Datei vorerst nur in einem Server-Codeblock (<code>if (false)</code>) einzubinden. Das ASP.NET AJAX-Team arbeitet an einer besseren Lösung.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andreas-schlapsi.at/2008/10/27/intellisense-fur-jquery-in-visual-studio-2008/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery: DOM-Elemente auswählen</title>
		<link>http://www.andreas-schlapsi.at/2008/10/10/jquery-dom-elemente-auswahlen/</link>
		<comments>http://www.andreas-schlapsi.at/2008/10/10/jquery-dom-elemente-auswahlen/#comments</comments>
		<pubDate>Thu, 09 Oct 2008 22:46:12 +0000</pubDate>
		<dc:creator>Andreas Schlapsi</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[JavaScript & HTML]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.andreas-schlapsi.at/?p=31</guid>
		<description><![CDATA[Im letzten Beitrag „Ein erster Blick auf jQuery“ haben wir uns die Grundlagen von jQuery angesehen. Diesmal sehen wir uns an, wie wir mit jQuery DOM-Elemente selektieren können. Selektoren Eine JavaScript-Applikation ändert die GUI, indem sie den Dokumentenbaum manipuliert. Das DOM bietet dafür die Methoden getElementById, getElementsByName oder getElementsByTagName. Mit jQuery geht&#8217;s einfacher. Zwei weitere [...]]]></description>
			<content:encoded><![CDATA[<p>
Im letzten Beitrag „<a href="http://www.andreas-schlapsi.at/2008/10/08/ein-erster-blick-auf-jquery/">Ein erster Blick auf jQuery</a>“ haben wir uns die Grundlagen von jQuery angesehen. Diesmal sehen wir uns an, wie wir mit jQuery DOM-Elemente selektieren können.
</p>
<p><span id="more-31"></span></p>
<h3>Selektoren</h3>
<p>
Eine JavaScript-Applikation ändert die GUI, indem sie den Dokumentenbaum manipuliert. Das <abbr title="Document Object Model">DOM</abbr> bietet dafür die Methoden <code>getElementById</code>, <code>getElementsByName</code> oder <code>getElementsByTagName</code>. Mit jQuery geht&#8217;s einfacher.
</p>
<p>
Zwei weitere Sprachen müssen häufig im Dokumentenbaum navigieren: <a href="http://www.w3.org/Style/CSS/">CSS</a> und <a href="http://www.w3.org/TR/xpath">XPath</a>. CSS- und XPath-Kenntnisse setze ich voraus.
</p>
<p>
Sehen wir uns einmal ein Beispiel an. Angenommen irgendwo in einem Dokument befindet sich folgendes Code-Schnipsel:
</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;MenuItem&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Datei<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>
Das DIV-Element findet man mit dem DOM-API mit folgendem Code:
</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> element <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'MenuItem'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>
Die Voraussetzung dafür ist, dass das gesuchte Element ein ID-Attribut besitzt. Mit CSS setzt man die Vordergrundfarbe des Elements so:
</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#MenuItem</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#fe4578</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>
Dabei ist „#MenuItem“ der CSS-Selektor. Mit jQuery kann man CSS-Selektoren für die Navigation im Dokumentenbaum verwenden:
</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#MenuItem&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    ...
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>
Dem $-Zeichen sind wir schon in der letzten Folge begegnet. Es handelt sich dabei um einen Alias für die Funktion <code>jQuery</code>. jQuery akzeptiert entweder ein DOM-Element oder einen Selektor als Argument.
</p>
<h3>Mehrere Elemente gleichzeitig manipulieren</h3>
<p>
Bisher haben wir immer nur ein DOM-Element bearbeitet. Doch was macht folgendes Code-Schnipsel?
</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.clickable&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    ...
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>
Der Selektor „.clickable“ wählt alle Elemente mit der CSS-Klasse „clickable“ und registriert darauf einen Click-Eventhandler. Mit jQuery können Sie also mehrere Elemente gleichzeitig bearbeiten.
</p>
<h3>Methoden-Verkettung</h3>
<p>
Der Rückgabewert jeder jQuery-Methode ist das jQuery-Objekt selbst. Daher können Methoden-Aufrufe verkettet werden.
</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;p&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;color&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;#800000&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;paragraph&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    ...
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>
In diesem Beispiel setzen wir die Vordergrundfarbe aller P-Elemente auf rot, fügen allen P-Elementen die CSS-Klasse „paragraph“ hinzu und registrieren auf allen P-Elementen einen Click-Eventhandler.
</p>
<p>
In diesem Beispiel sind wir zwei neuen Methoden begegnet: <code>css</code> und <code>addClass</code>. <code>css</code> setzt eine oder mehrere CSS-Eigenschaften. Mehrere CSS-Eigenschaften können so angegeben werden:
</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;p&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #3366CC;">&quot;color&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;#800000&quot;</span><span style="color: #339933;">,</span>
    <span style="color: #3366CC;">&quot;background-color&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;#000000&quot;</span><span style="color: #339933;">,</span>
    <span style="color: #3366CC;">&quot;text-weight&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;bold&quot;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>
<code>addClass</code> fügt eine CSS-Klasse hinzu.
</p>
<h3>Auswahl erweitern und einschränken</h3>
<p>
jQuery hat einige Methoden, die die Auswahl der DOM-Elemente erweitern oder einschränken. In Verbindung mit der Methodenverkettung ergeben sich daraus interessante Möglichkeiten.
</p>
<p>
Wenn Sie das folgende Beispiel starten, können Sie die Text aus- und einblenden, indem Sie auf die entsprechende Links klicken.
</p>
<p>
<a href="http://www.andreas-schlapsi.at/wp-content/uploads/2008/10/index.html" target="_blank">Beispiel starten</a> (in neuem Fenster)
</p>
<p>
Hier ist der Source-Code des Beispiels:
</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #00bbdd;">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; </span>
<span style="color: #00bbdd;">    &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;html<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;head<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>jQuery Sample<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;script</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;jquery.js&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;script</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;sample.js&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/head<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;a</span> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">&quot;#&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;activateLink&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Text 1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/a<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        Erster Text
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;a</span> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">&quot;#&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;activateLink&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Text 2<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/a<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        Zweiter Text
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/html<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>
Der JavaScript-Code für dieses Beispiel ist nur fünf Zeilen lang:
</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;a.activateLink&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">next</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;div&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">toggle</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>
Der Click-Eventhandler sucht ein DIV-Element, das dem geklickten Link unmittelbar folgt, und ändert dessen Sichtbarkeit.
</p>
<h3>Die Methode <code>filter</code></h3>
<p>
<a href="http://www.andreas-schlapsi.at/wp-content/uploads/2008/10/jquery_02_filter_methods.html" target="_blank">Beispiel starten</a> (in neuem Fenster)
</p>
<p>
Hier ist der HTML-Sourcecode:
</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #00bbdd;">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; </span>
<span style="color: #00bbdd;">    &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;html<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;head<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>jQuery 02 - Filter Methods<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;script</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;jquery.js&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;script</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;jquery_02_filter_methods.js&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/head<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ul<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;li<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;a</span> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">&quot;http://www.andreas-schlapsi.com&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;external_link&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Link 1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/a<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/li<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;li<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;a</span> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">&quot;http://www.jquery.com&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;external_link&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Link 2<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/a<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/li<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;li<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;a</span> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">&quot;http://ui.jquery.com&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;external_link&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Link 3<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/a<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/li<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ul<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ul<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;li<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;a</span> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">&quot;#&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;message_link&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Erste Nachricht<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/a<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/li<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;li<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;a</span> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">&quot;#&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;message_link&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Zweite Nachricht<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/a<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/li<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ul<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;MessageLabel&quot;</span> <span style="color: #000066;">style</span>=<span style="color: #ff0000;">&quot;border: 1px solid #000; background-color: #eee; padding: 1em;&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ul<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;li<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;a</span> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">&quot;http://www.google.com&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Ein normaler Link<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/a<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/li<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ul<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/html<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>
Und hier der JavaScript-Code:
</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;a&quot;</span><span style="color: #009900;">&#41;</span>
    .<span style="color: #660066;">filter</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.external_link&quot;</span><span style="color: #009900;">&#41;</span>
      .<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Sie verlassen die Seite.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
    .<span style="color: #660066;">end</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    .<span style="color: #660066;">filter</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.message_link&quot;</span><span style="color: #009900;">&#41;</span>
      .<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#MessageLabel&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
    .<span style="color: #660066;">end</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>
Das Beispiel filtert aus den selektierten Linkelementen jene heraus, die die Klasse „.external_link“ haben und registriert darauf einen Click-Eventhandler, der eine Messagebox anzeigt. Die Methode <code>end</code> hebt die Filterung wieder auf. Auf allen Linkelementen mit der Klasse „.message_link“ wird ein anderer Click-Eventhandler registriert, der den Textinhalt des geklickten Links in das DIV-Element mit der ID „MessageLabel“ kopiert. Die Methode <code>text</code> ohne Parameter liest den Textinhalt aus, statt ihn zu setzen.
</p>
<p>
Beachten Sie, dass der zweite Click-Eventhandler <code>false</code> zurückgibt. Bei einem Click-Eventhandler wird dadurch die Ereignisbehandlung abgebrochen, d.h. dass der Browser dem Link, der im Attribut <code>href</code> angegeben ist, nicht folgt.
</p>
<h3>jQuery-Dokumentation</h3>
<p>
Folgende Links auf die jQuery-Dokumentation enthalten detailliertere Informationen zu den Themen dieses Artikels:
</p>
<ul>
<li><a href="http://docs.jquery.com/Selectors">jQuery Documentation: Selectors</a></li>
<li><a href="http://docs.jquery.com/Traversing">jQuery Documentation: Traversing</a></li>
</ul>
<h3>Zusammenfassung</h3>
<p>
Dieses Mal haben wir gesehen, wie wir mit Selektoren ein oder mehrere DOM-Elemente finden und bearbeiten können. Die jQuery-Methoden geben das jQuery-Objekt zurück und können daher verkettet werden. Einige Methoden schränken die Auswahl ein oder erweitern diese.
</p>
<p>
In der nächsten Folge dieser Serie geht es um DOM-Manipulation und Effekte.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andreas-schlapsi.at/2008/10/10/jquery-dom-elemente-auswahlen/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Ein erster Blick auf jQuery</title>
		<link>http://www.andreas-schlapsi.at/2008/10/08/ein-erster-blick-auf-jquery/</link>
		<comments>http://www.andreas-schlapsi.at/2008/10/08/ein-erster-blick-auf-jquery/#comments</comments>
		<pubDate>Wed, 08 Oct 2008 21:55:34 +0000</pubDate>
		<dc:creator>Andreas Schlapsi</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[JavaScript & HTML]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.andreas-schlapsi.at/?p=28</guid>
		<description><![CDATA[Scott Guthrie und John Resig kündigten Ende September an, dass die nächste Version von Visual Studio die JavaScript-Library jQuery enthalten wird. Die Entwicklungsumgebung wird Intellisense für jQuery-Methoden bieten und die jQuery-Hilfe in das Hilfesystem integriert sein. Grund genug, um einen ersten Blick auf die JavaScript-Library zu werfen. Dieser Artikel ist der Beginn einer Blogserie, mit [...]]]></description>
			<content:encoded><![CDATA[<p>
<a href="http://weblogs.asp.net/scottgu/archive/2008/09/28/jquery-and-microsoft.aspx">Scott Guthrie</a> und <a href="http://jquery.com/blog/2008/09/28/jquery-microsoft-nokia/">John Resig</a> kündigten Ende September an, dass die nächste Version von Visual Studio die JavaScript-Library <a href="http://jquery.com/">jQuery</a> enthalten wird. Die Entwicklungsumgebung wird Intellisense für jQuery-Methoden bieten und die jQuery-Hilfe in das Hilfesystem integriert sein. Grund genug, um einen ersten Blick auf die JavaScript-Library zu werfen.
</p>
<p>
Dieser Artikel ist der Beginn einer Blogserie, mit der ich die Grundlagen von jQuery vorstellen möchte. In dieser Folge sehen wir uns ein einfaches jQuery-Script an.
</p>
<p><span id="more-28"></span></p>
<h3>Hello, world!</h3>
<p>
Um mit jQuery experimentieren und entwickeln zu können, <a href="http://docs.jquery.com/Downloading_jQuery">laden Sie die JavaScript-Library</a> von der Homepage runter. Das Beispiel wurde mit Version&nbsp;1.2.6 entwickelt und getestet. Es gibt drei Varianten für den Download:</p>
<ol>
<li><strong>Uncompressed</strong>&nbsp;-&nbsp;enthält den originalen JavaScript-Code mit Kommentaren und Whitespace.</li>
<li><strong>Packed</strong>&nbsp;-&nbsp;ist die kleinste Datei. Am Client wird aber JavaScript-Code ausgeführt, um den eigentlichen jQuery-Code zu entpacken, weshalb die Performance am schlechtesten ist.</li>
<li><strong>Minified</strong>&nbsp;-&nbsp;enthält den originalen JavaScript-Code ohne Kommentare und Whitespace. Diese Variante wird für Produktionssysteme empfohlen.</li>
</ol>
<p>Für unser erstes Beispiel kopieren Sie die heruntergeladene Datei unter dem Namen „jquery.js“ in ein beliebiges Verzeichnis, in dem Sie auch eine neue HTML-Datei mit folgendem Inhalt anlegen:
</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #00bbdd;">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; </span>
<span style="color: #00bbdd;">    &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;html<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;head<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>jQuery Sample<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;script</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;jquery.js&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;script</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      $(document).ready(function() {
        $(&quot;#Label&quot;).click(function() {
          $(this).text(&quot;Hello, world!&quot;);
        });
      });
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/head<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;Label&quot;</span> <span style="color: #000066;">style</span>=<span style="color: #ff0000;">&quot;border: 1px solid #000;&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      This is a test.
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/html<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>
Wenn Sie die Datei öffnen, zeigt der Browser den Text „This is a test.“ an. Wenn Sie darauf klicken, tauscht der JavaScript-Code den Text gegen „Hello, world!“ aus.
</p>
<p>
Der Startpunkt des Frameworks ist „$“, ein Alias für die Funktion <code>jQuery</code>, die als Argument einen Selektor oder ein DOM-Element erwartet. In unserem Beispiel verwenden wir die $-Funktion drei Mal: <code>$(document)</code>, <code>$(&quot;#Label&quot;)</code> und <code>$(this)</code>. <code>$(document)</code> und <code>$(this)</code> geben jeweils ein Objekt zurück, dessen Methoden auf die angegebenen DOM-Elemente wirken. <code>$(&quot;#Label&quot;)</code> verwendet einen CSS-Selektor, um das DIV-Element mit der ID „Label“ zu finden.
</p>
<h3>Das Ready-Ereignis</h3>
<p>
JavaScript-Code wird sofort nach dem Parsen ausgeführt. Zu diesem Zeitpunkt ist der Dokumentenbaum noch nicht vollständig aufgebaut, was zu Problemen führen kann.
</p>
<p>
JavaScript-Entwickler verwenden deshalb häufig das Load-Ereignis am <code>window</code>-Objekt für Initialisierungscode. Der Browser löst dieses Ereignis aus, sobald er die Seite geladen hat. Der Code wird aber erst ausgeführt, nachdem auch alle Bilder geladen wurden.
</p>
<p>
jQuery bietet deshalb das Ready-Ereignis an. jQuery wartet, bis das Dokument bereit ist, um bearbeitet zu werden, und löst dann das Ereignis aus.
</p>
<h3>Eventhandler</h3>
<p>
Eventhandler sind für jQuery einfache JavaScript-Funktionen. Wir haben in unserem Beispiel anonyme Funktionen verwendet (Zeilen&nbsp;8 und 9).
</p>
<p>
Unser Beispiel registriert einen Eventhandler für das Click-Ereignis am DIV-Element mit der ID „Label“. Ein DOM-Element löst das Click-Ereignis aus, wenn der Benutzer darauf mit der Maus klickt.
</p>
<p>
<strong>Hinweis:</strong> In Eventhandlern zeigt <code>this</code> auf das DOM-Element, das das Ereignis ausgelöst hat.</p>
<p>
Unser Beispiel verändert in Zeile&nbsp;10 im Click-Eventhandler des DIV-Elements den Textinhalt des Elements mit der Methode „text“:
</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Hello, world!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h3>Zusammenfassung</h3>
<p>
Der Startpunkt für jQuery ist die Funktion <code>jQuery</code> mit dem Alias „$“. Mit Selektoren referenzieren Sie DOM-Elemente, auf die Sie mit dem jQuery-API Eventhandler registrieren, DOM-Manipulationen durchführen oder Effekte aufrufen können.
</p>
<p>
Das Ready-Ereignis können Sie zur Initialisierung Ihrer JavaScript-Anwendung nutzen. Wie bei normalen JavaScript-Eventhandlern referenziert <code>this</code> in einer als Eventhandler registrierten Funktion das DOM-Element, das das Ereignis ausgelöst hat.
</p>
<p>
In der nächsten Folge wenden wir uns den jQuery-Selektoren zu.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andreas-schlapsi.at/2008/10/08/ein-erster-blick-auf-jquery/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

