Reputation:
I have ten divs with class pcre
in a single div whose id is huge
.How can I move div(having class=pcre) to last in div(id=huge) on mouseclick
with jQuery
I have tried
<div id="huge">
<div class="pcre">a</div>
<div class="pcre">b</div>
<div class="pcre">c</div>
<div class="pcre">d</div>
<div class="pcre">e</div>
<div class="pcre">f</div>
<div class="pcre">g</div>
<div class="pcre">h</div>
<div class="pcre">i</div>
<div class="pcre">j</div>
</div>
<script>
$(".pcre").click(function() {
$(this).appendTo("#huge");$(this).remove();
});
</script>
But its not working.
Upvotes: 0
Views: 96
Reputation: 34107
Hiya demo http://jsfiddle.net/TPHy8/4/ or http://jsfiddle.net/TPHy8/6/
You have extra ,
comma in your code. remove it and bingo!! B-) Anyhoo and '.remove` can be removed.
Hope this helps bruv! please let me know if I am missing anything else!
code
updated
$(".pcre").click(function(){
$(this).appendTo("#huge");
// $(this).remove();
});
$(".pcre").click(function(){
$(this).appendTo("#huge");
$(this).remove();
});
Upvotes: 1
Reputation: 2223
You have an extra comma before your function(), and you also don't need the .remove();
<div id="huge">
<div class="pcre">a</div>
<div class="pcre">b</div>
<div class="pcre">c</div>
<div class="pcre">d</div>
<div class="pcre">e</div>
<div class="pcre">f</div>
<div class="pcre">g</div>
<div class="pcre">h</div>
<div class="pcre">i</div>
<div class="pcre">j</div>
</div>
<script>
$(".pcre").click(function(){
$(this).appendTo("#huge");
});</script>
Upvotes: 1