Take the 2-minute tour ×

I would like to select only the "mixitup" elements from the same level clicking on one of this elements.

<div data-id="0">
    <div class="mixitup">1</div>
    <div class="mixitup">2</div>
    <div class="mixitup">3</div>
<div data-id="1">
    <div class="mixitup">4</div>
    <div class="mixitup">5</div>
    <div class="mixitup">6</div>

I mean. If I click in the DIV with contents = 4, I would like to select the DIVs 4,5 and 6.

Someone know a way to do it? thanks

share|improve this question
add comment

4 Answers

If you want to select all of them including the one you picked. http://jsfiddle.net/kwnDS/1/

$('.mixitup').on('click', function() {
share|improve this answer
Don't forget to deselect any previous matches. –  Anthony Apr 6 '12 at 23:16
add comment

Siblings, including the self element, would be accomplished by finding the parent and select all of its children (not descendants):

$(".mixitup").click(function () {
share|improve this answer
it should be $(this).parent().children("div.mixitup").doSomething(); –  ocanal Apr 6 '12 at 22:43
I agree, but I feel like it's unnecessary if you know you want to select all of the siblings. If there were other children in the parent div, I would definitely add the selector for the children(). Ignoring it in this case (if applicable) reduces that extra processing. –  Ian Apr 7 '12 at 3:53
add comment

To avoid having to select the clicked element's parent, you should simply select it's siblings and itself:

$(".mixitup").on("click", function(e) {


share|improve this answer
add comment

What you need is the siblings selector:

  $(this).siblings('.mixitup'); //this selects siblings of an element;
share|improve this answer
add comment

Your Answer


