Home › Forums › JavaScript › [Extraordinary Solved] JQuery Plugin Patterns that can be Applied for Multiple Elements › Re: [Extraordinary Solved] JQuery Plugin Patterns that can be Applied for Multiple Elements
June 9, 2012 at 8:35 am
#104136
Mottie
Member
Hi Hompimpa!
The main issue is that the i
is indexed from each selector so when '#tab1, #tab2, #tab3'
is used, it counts 0, 1, 2.
But when three separate calls to the plugin are made, the count always starts from 0. This is why the tab content is getting mixed between the instances.
So, the easiest solution is to apply a unique value to each call, so instead define i
like this:
i = this.id;
Here is an updated demo.
Also, it is good practice to target the tabs from it’s own wrapper, so instead of depending on i
to be unique:
$('.tabs' + i)
find the tab this way:
$t.find('.tabs' + i)