More importantly you can do this with CSS instead of javascript:

http://www.hunlock.com/blogs/Attach_icons_to_anything_with_CSS.

http://www.askthecssguy.com/2006/12/showing_hyperlink_cues_with_cs_1.html 


____________________________________
 
Andy Matthews
Senior Coldfusion Developer
 
Office:  877.707.5467 x747
Direct:  615.627.9747
Fax:  615.467.6249
[EMAIL PROTECTED]
www.dealerskins.com

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of Klaus Hartl
Sent: Tuesday, January 09, 2007 5:06 PM
To: jQuery Discussion.
Subject: Re: [jQuery] Play around with JQuery

Olaf Bosch schrieb:
> Olaf Bosch schrieb:
> 
>> Errors are, all Links are find. $("#text a").favicon(); is the Selector.
> 
> Oh, i stupid, i close not the DIV, dammit :)
> 

That's not the problem but inside the each loop "this" is a DOM element and
not a jQuery object, thus this.append(cue) won't work.

It has to be: jQuery(this).append(cue)

Also, if you intend to make that plugin chainable (jQuery.fn.favicon) you
have to use:

return this.each(...);

And maybe you don't need to use all the regular expressions to parse the
domain. There are properties ready to use:

this.hostname would give you "www.google.com"

All in all, try this:

jQuery.fn.favicon = function () {
   return this.each(function() {
     var hoststring = /^http:/i;
     var hrefvalue = this.getAttribute("href");
     if (hrefvalue.search(hoststring) != -1) {
       var domain = this.hostname;
       var cuesrc = "http://"+domain+"/favicon.ico";;
       var cue = "<img class=\"favicon\" src=\""+cuesrc+"\" alt=\"\" />";
       jQuery(this).append(cue);
     }
   });
};


-- Klaus




_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/

Reply via email to