[jQuery] jquery inside a loop... need suggestions to improvecode

[jQuery] jquery inside a loop... need suggestions to improvecode

<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:st1="urn:schemas-microsoft-com:office:smarttags" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=Content-Type content="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 11 (filtered medium)">
<!--[if !mso]>
<style>
v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style>
<![endif]--><o:SmartTagType
namespaceuri="urn:schemas-microsoft-com:office:smarttags" name="PersonName"/>
<!--[if !mso]>
<style>
st1\:*{behavior:url(#default#ieooui) }
</style>
<![endif]-->
<style>
<!--
/* Font Definitions */
@font-face
{font-family:Wingdings;
panose-1:5 0 0 0 0 0 0 0 0 0;}
@font-face
{font-family:Tahoma;
panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman";}
a:link, span.MsoHyperlink
{color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{color:blue;
text-decoration:underline;}
p
{mso-margin-top-alt:auto;
margin-right:0in;
mso-margin-bottom-alt:auto;
margin-left:0in;
font-size:12.0pt;
font-family:"Times New Roman";}
span.EmailStyle20
{mso-style-type:personal-reply;
font-family:Arial;
color:navy;}
@page Section1
{size:8.5in 11.0in;
margin:1.0in 1.25in 1.0in 1.25in;}
div.Section1
{page:Section1;}
-->
</style>
</head>
<body lang=EN-US link=blue vlink=blue>
<div class=Section1>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>Hey thanks </span></font><font size=2
color="#333399" face=Arial><span style='font-size:10.0pt;font-family:Arial;
color:#333399'>Daemach</span></font><font size=2 color=navy face=Arial><span
style='font-size:10.0pt;font-family:Arial;color:navy'>. I got this to work for
my purpose.  Btw, there was also a    + "]"  
that was missing from the script you sent.  Thanks for getting me started
though.<o:p></o:p></span></font>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font>
<div style='border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt'>
<div>
<div link=blue vlink=blue>
<div>

<font size=2 color=navy face=Arial><span style='font-size:10.0pt;font-family:
Arial;color:navy'> </span></font><o:p></o:p>


<div style='border:none;border-left:solid windowtext 1.5pt;padding:0in 0in 0in 4.0pt;
border-color:-moz-use-text-color -moz-use-text-color -moz-use-text-color blue'>
<div>
<div class=MsoNormal align=center style='text-align:center'><font size=3
face="Times New Roman"><span style='font-size:12.0pt'>
<hr size=2 width="100%" align=center>
</span></font></div>

<b><font size=2 face=Tahoma><span style='font-size:10.0pt;font-family:Tahoma;
font-weight:bold'>From:</span></font></b><font size=2 face=Tahoma><span
style='font-size:10.0pt;font-family:Tahoma'> <a
href="mailto:discuss-bounces@jquery.com" target="_blank">discuss-bounces@jquery.com</a>
[mailto:<a href="mailto:discuss-bounces@jquery.com" target="_blank"> discuss-bounces@jquery.com</a>]
<b><span style='font-weight:bold'>On Behalf Of </span></b>Daemach
<b><span style='font-weight:bold'>Sent:</span></b> Friday, March 16, 2007 11:46
AM
<b><span style='font-weight:bold'>To:</span></b> <st1:PersonName w:st="on">jQuery
Discussion.</st1:PersonName>
<b><span style='font-weight:bold'>Subject:</span></b> Re: [jQuery] jquery
inside a loop... need suggestions to improvecode</span></font><o:p></o:p>











</div>
<div><span id="q_1115c5027399ea86_1">

<font size=3 face="Times New Roman"><span style='font-size:12.0pt'> <o:p></o:p></span></font>


<p style='margin-bottom:12.0pt'><font size=3 face="Times New Roman"><span
style='font-size:12.0pt'>Try this:
<cfoutput query="myQuery">
<a class="tooltip" id="aid_#myQuery.id#"
href="somepage.cfm?to=#myquery.id#">#myQuery.text#</a>
<img id="imgid_#myQuery.id#"
src="/thumbnails/#myQuery.image#" />
</cfloop>
<script type="text/javascript">
    $(document).ready(function(){
        $("img.tooltip").hide();
       
       
$("a.tooltip").each(function(){       
           
$(this).hover(function(){
               
$("img[@id=imgid_" + this.id.split("_")[1]).show();
            },function(){
               
$("img[@id=imgid_" + this.id.split ("_")[1]).hide();
            });
        })
    });
 </script><o:p></o:p></span></font>
<div>

<font size=3 face="Times New Roman"><span style='font-size:12.0pt'>On
3/16/07, <b><span style='font-weight:bold'>Michael E. Carluen</span></b> <<a
href="mailto:cf_mecarluen@comcast.net" target="_blank">
cf_mecarluen@comcast.net</a>> wrote:<o:p></o:p></span></font>



<div link=blue vlink=purple>
<div>

<font size=2 face=Arial><span style='font-size:10.0pt;font-family:Arial'>Hello
(CF) jQuerians,</span></font><o:p></o:p>


<font size=2 face=Arial><span style='font-size:10.0pt;font-family:Arial'> </span></font><o:p></o:p>


<font size=2 face=Arial><span style='font-size:10.0pt;font-family:Arial'>I
currently have a working code but I would really like to improve and make it
more efficient. Your suggestions will be great.</span></font><o:p></o:p>


<font size=2 face=Arial><span style='font-size:10.0pt;font-family:Arial'>Right
now, I have a jquery script inside a loop (cfloop). The jquery is a just simple
tooltip-like functionality, that shows and hides a thumbnail image on a text
description hover. The image is loaded from a cfquery id variable assigned into
a div id.  What I'd like is to remove the jquery script outside of the
cfloop, so it does not redundantly iterate when the page runs. The simplified
code is as follows:</span></font><o:p></o:p>






<font size=2 face=Arial><span style='font-size:10.0pt;font-family:Arial'> </span></font><o:p></o:p>


<font size=2 face=Arial><span style='font-size:10.0pt;font-family:Arial'><cfloop
query="myQuery"></span></font><o:p></o:p>


<font size=2 face=Arial><span style='font-size:10.0pt;font-family:Arial'>           
<a id="aid#myQuery.id#"
href="somepage.cfm?to=#myquery.id#">#myQuery.text#</a></span></font><o:p></o:p>


<font size=2 face=Arial><span style='font-size:10.0pt;font-family:Arial'> </span></font><o:p></o:p>


<font size=2 face=Arial><span style='font-size:10.0pt;font-family:Arial'>           
<div id="imgid#myQuery.id#"><img
src="/thumbnails/#myQuery.image#" /></div></span></font><o:p></o:p>


<font size=2 face=Arial><span style='font-size:10.0pt;font-family:Arial'>           
<script type="text/javascript"></span></font><o:p></o:p>


<font size=2 face=Arial><span style='font-size:10.0pt;font-family:Arial'>           
          $("##imgid#myQuery.id#").hide();
</span></font><o:p></o:p>


<font size=2 face=Arial><span style='font-size:10.0pt;font-family:Arial'>          
           $(function(){
</span></font><o:p></o:p>


<font size=2 face=Arial><span style='font-size:10.0pt;font-family:Arial'>                           
$("##aid#myQuery.id#").hover(function(){ </span></font><o:p></o:p>


<font size=2 face=Arial><span style='font-size:10.0pt;font-family:Arial'>                           
$("##imgid#myQuery.id#").show(); </span></font><o:p></o:p>


<font size=2 face=Arial><span style='font-size:10.0pt;font-family:Arial'>                        
},function(){ </span></font><o:p></o:p>


<font size=2 face=Arial><span style='font-size:10.0pt;font-family:Arial'>                         
  $("##imgid#myQuery.id#").hide(); </span></font><o:p></o:p>


<font size=2 face=Arial><span style='font-size:10.0pt;font-family:Arial'>                         
});       </span></font><o:p></o:p>


<font size=2 face=Arial><span style='font-size:10.0pt;font-family:Arial'>                      
});</span></font><o:p></o:p>


<font size=2 face=Arial><span style='font-size:10.0pt;font-family:Arial'>            
</script></span></font><o:p></o:p>


<font size=2 face=Arial><span style='font-size:10.0pt;font-family:Arial'></cfloop></span></font><o:p></o:p>


<font size=2 face=Arial><span style='font-size:10.0pt;font-family:Arial'> </span></font><o:p></o:p>


<font size=2 face=Arial><span style='font-size:10.0pt;font-family:Arial'>If
the answer seems too obvious for you, then I must say that its been a long week
for me… I just need a brain boost from someone…. </span></font><font
size=2 face=Wingdings><span style='font-size:10.0pt;font-family:Wingdings'>J</span></font><o:p></o:p>



<font size=2 face=Arial><span style='font-size:10.0pt;font-family:Arial'> </span></font><o:p></o:p>


<font size=2 face=Arial><span style='font-size:10.0pt;font-family:Arial'>Thank
you very much in advance, for your suggestions.</span></font><o:p></o:p>


<font size=2 face=Arial><span style='font-size:10.0pt;font-family:Arial'> </span></font><o:p></o:p>


<font size=2 face=Arial><span style='font-size:10.0pt;font-family:Arial'>Michael</span></font><o:p></o:p>


<font size=2 face=Arial><span style='font-size:10.0pt;font-family:Arial'> </span></font><o:p></o:p>


<font size=2 face=Arial><span style='font-size:10.0pt;font-family:Arial'> </span></font><o:p></o:p>


<font size=2 face=Arial><span style='font-size:10.0pt;font-family:Arial'> </span></font><o:p></o:p>


</div>
</div>
<p style='margin-bottom:12.0pt'><font size=3 face="Times New Roman"><span
style='font-size:12.0pt'>
_______________________________________________
jQuery mailing list
<a href="mailto:discuss@jquery.com" target="_blank">discuss@jquery.com</a>
<a href="http://jquery.com/discuss/" target="_blank">http://jquery.com/discuss/</a><o:p></o:p></span></font>
</div>

<font size=3 face="Times New Roman"><span style='font-size:12.0pt'> <o:p></o:p></span></font>


</div>
</div>
</div>
</div>
</span>
<p class=MsoNormal style='margin-bottom:12.0pt'><font size=3
face="Times New Roman"><span style='font-size:12.0pt'>
_______________________________________________
jQuery mailing list
<a href="mailto:discuss@jquery.com">discuss@jquery.com</a>
<a href="http://jquery.com/discuss/" target="_blank">http://jquery.com/discuss/</a><o:p></o:p></span></font>
</div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'><o:p> </o:p></span></font>
</div>
</div>
</body>
</html>
_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/