1

How do I set the values to the callback function, so that it's saved and ready to fire when the element is clicked?

for (i=0; i < ELEMENTS-1; i++) {
    array[i].click(function(){
        array[i].insertAfter(array[i+1]); 
        //other stuff
    });
}

array[] just contains a bunch of divs.

    <div class="wrapper">
        <div id="one" class="tile">One</div>
        <div id="two" class="tile">Two</div>
        <div id="three" class="tile">Three</div>
        <div id="four" class="tile">Four</div>
    </div>

When a div is clicked, I want it to move down the list.

7
  • This is one of the most frequent questions here, see link. Commented Apr 17, 2014 at 12:54
  • @mshsayem I don't think you understand the problem Commented Apr 17, 2014 at 12:55
  • @dystroy - While it is one of the most commonly asked questions here -- if you've never run into it before you have no idea what to even LOOK for when trying to solve it. You have to admit, it is pretty non-obvious first time you run into it. Commented Apr 17, 2014 at 12:56
  • @JeremyJStarcher Yes. No need for downvotes (or not too much). But now we should close it properly. Commented Apr 17, 2014 at 12:57
  • Here's another similar QA with other explanations. Commented Apr 17, 2014 at 12:59

1 Answer 1

0

With jQuery, you can use:

$('.wrapper div').click(function() {
    $(this).insertAfter($(this).next());    
});

Fiddle Demo

Sign up to request clarification or add additional context in comments.

3 Comments

This won't help OP learn how to solve this general class of problem
@dystroy Since you already post comments related to his problem, do I need to post it again in my answer?
note : I'm not the downvoter. If it works I don't see any good reason to downvote

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.