Siri: jQuery: this und $(this)

Beitrag lesen

Hallo,

Danke für die Antwort!

Das wirft eine neue Frage auf. Ein beliebtes Konstrukt scheint ja zu sein (aus einem Plugin):

(function ($) {  
  
  $.fn.shareButtons = function (url, options) {  
  
    $(this).addClass("foo");  
  
    // The plugin supports multiple share buttons on the page.  
    // Here we loop the supplied elements and initialize it.  
    this.each(function(i){  
       var elem = $(this);  
  
       // Do something  
  
    }  
  
  
  };  
	  
})(jQuery);

Aufgerufen wird das Plugin mit:

$(function (){  
  $('.socialShare').shareButtons(url, options);  
}  

Das wiederum ziel auf alle Elemente der Klasse socialShare. Wird durch das each im Plugin sozusagen alles doppelt gemoppelt?  $(this).addClass("foo"); gilt ja für alle Elemente dieser Klasse, ohne dass man vorher mit each darüber loopt! Mhmm...

Viele Grüße
Siri