On my page, I have multiple div with specified class which have 2 span elements. I want to check if the second element has a particular class, add new span object between the 2 span.
var allrtSp = $(".rtSp");
for (i = 0; i < allrtSp.length; i++) {
var cls= $(allrtSp[i]).next().attr('class');
var newSpan;
if (cls != 'rtMinus' && cls != 'rtPlus')
{
$(allrtSp[i]).add('<span class="rtNoChild"></span>');
}
}
I used the above code, but this is not working.
Shouldn’t you be using
The code you have will add a new span as a child of allrtSp[i] as opposed to between it and the next span.