<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" 
      xmlns:thr="http://purl.org/syndication/thread/1.0">
  <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/04/jquery-wild-card-example.html" />
  <link rel="self" type="application/atom+xml" href="http://www.insideria.com/atom.xml" />
  <id>tag:www.insideria.com,2009://34/tag:www.insideria.com,2009://34.35870-</id>
  <updated>2009-11-16T15:06:55Z</updated>
  <title>Comments for jQuery Wild Card Example (http://www.insideria.com/2009/04/jquery-wild-card-example.html)</title>
  <generator uri="http://www.sixapart.com/movabletype/">Movable Type 4.21-en</generator>
  <entry>
    <id>tag:www.insideria.com,2009://34.35870</id>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/04/jquery-wild-card-example.html" />
    <link rel="service.edit" type="application/atom+xml" href="http://blogs.oreilly.com/cgi-bin/mt/mt-atom.cgi/weblog/blog_id=34/entry_id=35870" title="jQuery Wild Card Example" />
    <published>2009-04-15T02:23:14Z</published>
    <updated>2009-04-15T02:56:16Z</updated>
    <title>jQuery Wild Card Example</title>
    <summary>Quick example of a wildcard selector.</summary>
    <author>
      <name>Raymond Camden</name>
      <uri>http://www.coldfusionjedi.com</uri>
    </author>
    
    <category term="Blogs" />
    
    <content type="html" xml:lang="en" xml:base="http://www.insideria.com/">
      <![CDATA[This came in as a question today and I thought it would make a great blog entry. (I tend to use questions as blog fodder on my <a href="http://www.coldfusionjedi.com">other blog</a> as well. So please, send in your questions!) Matthew asks:
<p/>
<blockquote>
<p>
I am having a hard time trying to use wildcards in my jquery as selectors.
For example get all classes that begin with "ray_"  so ray_green, ray_blue, ray_red. I tried $('.ray_*'), but that returns 0 items.
</p>
</blockquote>
<p/>
I began by creating a simple page with various items making use of classes that matched what Matthew wanted to find.
<p/>
 <div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>
&lt;<span class="category2">html</span>&gt;

&lt;head&gt;
&lt;script src="<span class="quote">jquery/jquery.js</span>"&gt;&lt;/script&gt;
&lt;script&gt;
$(document).ready(<span class="category1">function</span>() {
 	$("<span class="quote">#testBtn</span>").click(<span class="category1">function</span>() {
  		
  	})
})

&lt;/script&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;p&gt;
&lt;button id="<span class="quote">testBtn</span>"&gt;Test&lt;/button&gt;
&lt;/p&gt;

&lt;p <span class="category1">class</span>="<span class="quote">ray_cool</span>"&gt;
	ray cool <span class="category1">class</span>
&lt;/p&gt;

&lt;p <span class="category1">class</span>="<span class="quote">notray_cool</span>"&gt;
	notray cool <span class="category1">class</span>
&lt;/p&gt;

&lt;p <span class="category1">class</span>="<span class="quote">ray_cool</span>"&gt;
	ray cool <span class="category1">class</span>
&lt;/p&gt;

&lt;div <span class="category1">class</span>="<span class="quote">ray_hot</span>"&gt;
	ray hot <span class="category1">class</span>
&lt;/div&gt;

&lt;div <span class="category1">class</span>="<span class="quote">notray_hot</span>"&gt;
	notray hot <span class="category1">class</span>
&lt;/div&gt;

&lt;/body&gt;
&lt;/<span class="category2">html</span>&gt;</pre>
</code>

</div></div>
<p/>
I've got a set of items here, some P tags some DIV tags. Some use classes named ray_Something, and some use notray_Something. Given this set, we need the selector to find any item using a class that begins with ray_. I've got the jQuery code on top, but no selector just yet. Those of you who know jQuery wll can recognize the mistake Matthew made in his selector: $('.ray_*') The wildcards only (at least as far as I know now) only apply to matches based on attributes. So while .X works as a nice shortcut for the class, it won't work with the wildcard. 
<p/>
But don't forget - .X means match any item using the class X. Class is an attribute as well. A quick rewrite of his selector that works is: $("*[class^=ray]").hide()
<p/>
The * will match any html, and the [class^=ray] will further filter it down to items with a class that begins with ray. The .hide() was just may way to test the functionality. Here is the complete code block for my working demo.
<p/>

 <div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>
&lt;<span class="category2">html</span>&gt;

&lt;head&gt;
&lt;script src="<span class="quote">jquery/jquery.js</span>"&gt;&lt;/script&gt;
&lt;script&gt;
$(document).ready(<span class="category1">function</span>() {
 	$("<span class="quote">#testBtn</span>").click(<span class="category1">function</span>() {
  	
  		$("<span class="quote">*[class^=ray]</span>").<span class="category2">hide</span>()		
  	
  	})
})

&lt;/script&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;p&gt;
&lt;button id="<span class="quote">testBtn</span>"&gt;Test&lt;/button&gt;
&lt;/p&gt;

&lt;p <span class="category1">class</span>="<span class="quote">ray_cool</span>"&gt;
	ray cool <span class="category1">class</span>
&lt;/p&gt;

&lt;p <span class="category1">class</span>="<span class="quote">notray_cool</span>"&gt;
	notray cool <span class="category1">class</span>
&lt;/p&gt;

&lt;p <span class="category1">class</span>="<span class="quote">ray_cool</span>"&gt;
	ray cool <span class="category1">class</span>
&lt;/p&gt;

&lt;div <span class="category1">class</span>="<span class="quote">ray_hot</span>"&gt;
	ray hot <span class="category1">class</span>
&lt;/div&gt;

&lt;div <span class="category1">class</span>="<span class="quote">notray_hot</span>"&gt;
	notray hot <span class="category1">class</span>
&lt;/div&gt;

&lt;/body&gt;
&lt;/<span class="category2">html</span>&gt;</pre>
</code>

</div></div>

<p/>
As a last note - it sure would be nice to have a way to test selectors quicker. I'm working on something in this area now and hope to have something to share next week.]]>
      
    </content>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2009://34.35870-comment:2057566</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2009://34.35870" type="text/html" href="http://www.insideria.com/2009/04/jquery-wild-card-example.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/04/jquery-wild-card-example.html#comment-2057566" />
    <title>Comment from anthony on 2009-04-15</title>
    <author>
        <name>anthony</name>
        <uri>http://www.fojasaur.us</uri>
    </author>
    <content type="html" xml:lang="en" xml:base="http://www.fojasaur.us">
        <![CDATA[<p>You actually dont even need the *.  You can just use $("[class^=ray]").</p>]]>
    </content>
    <published>2009-04-15T13:52:22Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2009://34.35870-comment:2057569</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2009://34.35870" type="text/html" href="http://www.insideria.com/2009/04/jquery-wild-card-example.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/04/jquery-wild-card-example.html#comment-2057569" />
    <title>Comment from Raymond Camden on 2009-04-15</title>
    <author>
        <name>Raymond Camden</name>
        <uri>http://www.coldfusionjedi.com</uri>
    </author>
    <content type="html" xml:lang="en" xml:base="http://www.coldfusionjedi.com">
        <![CDATA[<p>Wow, didn't know that. Thanks for sharing it.</p>]]>
    </content>
    <published>2009-04-15T15:26:09Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2009://34.35870-comment:2057582</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2009://34.35870" type="text/html" href="http://www.insideria.com/2009/04/jquery-wild-card-example.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/04/jquery-wild-card-example.html#comment-2057582" />
    <title>Comment from cody lindley on 2009-04-15</title>
    <author>
        <name>cody lindley</name>
        <uri>http://www.codylindley.com</uri>
    </author>
    <content type="html" xml:lang="en" xml:base="http://www.codylindley.com">
        <![CDATA[<p>For situations that are not covered by selectors you can also use filter() and pass it a function...used to filter out elements that do not match the specified function. This is the next solution when a combination of selectors and the find() or filter() will not do. Essentially, you can create your own test.</p>

<p><a href="http://docs.jquery.com/Traversing/filter#fn">http://docs.jquery.com/Traversing/filter#fn</a></p>

<p>cody</p>]]>
    </content>
    <published>2009-04-15T19:11:20Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2009://34.35870-comment:2058665</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2009://34.35870" type="text/html" href="http://www.insideria.com/2009/04/jquery-wild-card-example.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/04/jquery-wild-card-example.html#comment-2058665" />
    <title>Comment from Mir on 2009-04-30</title>
    <author>
        <name>Mir</name>
        <uri></uri>
    </author>
    <content type="html" xml:lang="en" xml:base="">
        <![CDATA[<p>This was very useful. I had been struggling to find some code which explains how wildcard search works, this example just made is so easy to understand.</p>

<p>Thanks<br />
Mir<br />
</p>]]>
    </content>
    <published>2009-04-30T19:56:12Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2009://34.35870-comment:2065829</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2009://34.35870" type="text/html" href="http://www.insideria.com/2009/04/jquery-wild-card-example.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/04/jquery-wild-card-example.html#comment-2065829" />
    <title>Comment from mikrogroove on 2009-06-09</title>
    <author>
        <name>mikrogroove</name>
        <uri></uri>
    </author>
    <content type="html" xml:lang="en" xml:base="">
        <![CDATA[<p>Erm... this may not be an option for Matthew but why doesn't he just use separate class names instead? E.g. class="ray cool", class="notray cool", class="ray hot" and class="notray hot". They can then be used in CSS selectors like this: p.ray.hot{} or p.notray.hot{} etc and in jQuery with $('.ray, .hot') or $('.notray, .hot') Just a thought... </p>]]>
    </content>
    <published>2009-06-09T15:56:03Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2009://34.35870-comment:2068501</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2009://34.35870" type="text/html" href="http://www.insideria.com/2009/04/jquery-wild-card-example.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/04/jquery-wild-card-example.html#comment-2068501" />
    <title>Comment from Bonus Chilipoker on 2009-07-17</title>
    <author>
        <name>Bonus Chilipoker</name>
        <uri>http://www.bonus-chilipoker.com/</uri>
    </author>
    <content type="html" xml:lang="en" xml:base="http://www.bonus-chilipoker.com/">
        <![CDATA[<p>Is it possible to have a demo ?</p>]]>
    </content>
    <published>2009-07-18T01:18:23Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2009://34.35870-comment:2068503</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2009://34.35870" type="text/html" href="http://www.insideria.com/2009/04/jquery-wild-card-example.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/04/jquery-wild-card-example.html#comment-2068503" />
    <title>Comment from Raymond Camden on 2009-07-17</title>
    <author>
        <name>Raymond Camden</name>
        <uri>http://www.coldfusionjedi.com</uri>
    </author>
    <content type="html" xml:lang="en" xml:base="http://www.coldfusionjedi.com">
        <![CDATA[<p>I don't have one online, but you could just cut and paste the code above.</p>]]>
    </content>
    <published>2009-07-18T03:09:53Z</published>
  </entry>

</feed
