I have the following dom :
<div class="test">1</div>
<div class="test">2</div>
<div class="test">3</div>
<div class="test">4</div>
I would like to add before the nth test element a new element.
I am able to add a new element for all the test element with this code :
var newElement = "div class=\"test-new\"";
$(".test").before(newElement);
But I am not able to select only the desired element thanks to an index(example : 3), these 2 codes throws an error :
var newElement = "div class=\"test-new\"";
$(".test")(3).before(newElement);
$(".test")[3].before(newElement);