I’m trying to work with a jQuery plug-in which can work with a list of jquery object passed by invoking the plug-in.
The plugin works perfect If I pass a list of children, but I get problems if the selectors are once per parent, here is the example:
// this works, every element is treated independently
<script>
$('.image').plugInName ();
</script>
<div>
<div class="image"></div>
<div class="image"></div>
<div class="image"></div>
</div>
the problem is here:
// this won't work, every element is treated as the first one
<script>
$('.image').plugInName ();
</script>
<div>
<div class="image"></div>
</div>
<div>
<div class="image"></div>
</div>
<div>
<div class="image"></div>
</div>
Inside the plug-in I’ve used a for loop to make the objects independent.
I know I can use an id, I was just wonder if there was some alternative solution
Should be
Using
.index()was giving you the index of the element within its parent.http://jsfiddle.net/CFPTa/17/