Reputation: 422
I want to select an element and append this after other:
Using this dont work:
$('.sub'+$(this).val()).appendTo($(this).parent().parent().parent().parent());
the dom is:
<div class="sub1"></div>
<label></label>
Expect this:
<label></label>
<div class="sub1"></div>
the really dom:
the task is append the div after the label, i search this label per a input.subN and pick de parentparentparentparentparent
Upvotes: 0
Views: 84
Reputation: 380
Not sure about what you're trying to do, but here goes: If you need to simply move the label to be before the div, do this:
$("label").remove().insertBefore(".sub1");
If you need to move the div to be after label, do this:
$(".sub1").remove().insertAfter("label");
See here: http://jsfiddle.net/QpP9J/
Upvotes: 2
Reputation: 4376
if you just want to add your label before the other element, use prepend. http://api.jquery.com/prepend/
Upvotes: 1