Reputation: 29514
i am having two divs ,
<div id="input text">
<fieldset>
</fieldset>
</div>
<div id=1>
</div>
in my JQuery i am trying to append some elements to the Div that is previous to #1 how to do so..
$("<p>title</p>").appendTo(previous to 1 and inside fieldset );
since i am having many such divs i am trying to append using previous to 1 ??please suggest me...
Upvotes: 2
Views: 2595
Reputation: 12488
Shortest version:
$("<p>title</p>").appendTo($("#1").prevAll("div:first").find("fieldset"));
Expanded version:
/* 1 */ var $destination = $("#1")
/* 2 */ .prevAll("div:first")
/* 3 */ .find("fieldset");
/* 4 */ $("<p>title</p>").appendTo($destination);
Upvotes: 3