I have a container and inside that I have several anchor tags. These anchor tags has same class names. Now I want to get all anchor tags with class name lets say clickMe inside container. and apply a plugin to only them.
here is what I have
<div class="container">
<a href="#" class="button" rel="btn1">Task box 1</a><br />
<a href="#" class="button" rel="btn2">Task box 2</a><br />
<a href="#" class="button" rel="btn3">Task box 3</a><br />
<a href="#" class="button" rel="btn4">Task box 4</a><br />
</div>
EDIT
Here is my plugin code
(function() {
$.fn.tasks = function(userOptions){
this.each(function() {
var opts = $.extend({
'speed' : 200
}, userOptions);
var ael = $(this).find('a.button');
var container = $(this); //'.' + opts.container;
var speed = opts.speed;
//alert(container);
var backdrop = $('<div></div>').addClass('backdrop');
var box = $('<div></div>').addClass('box');
$(ael).click(function() {
//alert(speed);
var rel = $(this).attr(rel);
alert("rel");
$(box).html(rel);
$(container).append(backdrop, box);
$(backdrop).animate({'opacity' : '.50'}, speed, 'linear');
$(box).animate({'right' : '0'}, speed, 'linear');
$(backdrop,box).css('display', 'block');
});
$(backdrop).click(function() {
closeBox();
});
function closeBox() {
$(box).animate({'right' : '-500'}, speed, 'linear', function() {
$(backdrop).animate({'opacity' : '.0'}, speed, 'linear', function() {
$(backdrop,box).css('display', 'none');
});
});
}
});
}
}(jQuery))
Assuming I’ve understood your question correctly, it’s as simple as this:
.container– Finds elements with class “container”a.clickMe– Finds descendants of.containerthat areaelements with class “clickMe”You should probably start (as mentioned in comments on your question) by reading the jQuery documentation, as this is pretty much as basic as it gets.
Edit (see comments)
In your plugin,
thiswill most likely refer to the set of matched elements. You can therefore iterate overthisusingeach, and usefindto get the descendantaelements: