0

I tried to append an option value in a particular position/index using jquery.

This is my code :

 function refreshDropDown(target,option){
var arrDatabases = getDatabases();  
var numOfDatabases = arrDatabases.length;
var hasPe= jQuery.inArray("pe",arrDatabases) >=0 ;
var onlyPe= (jQuery.inArray("pe",arrDatabases) >=0 && numOfDatabases == 1);

        if( !hasPe && !onlyPe && numOfDatabases !=0){
            jQuery(".lookForSelector             option[value='Publishers']").remove();

**jQuery(target).append(jQuery('<option>     </option>').val('Publishers').html('Publisher'));**

}
}

In this above code i want to append the value "publishers" with caption "publisher" at 19th position. Now it is getting appended in the last index. the value for the variable target is ".lookForSelector".

Appreciate your timely help.

4

1 回答 1

3

如果您知道要附加到的目标:

$(target + ' :nth-child(19)').after("<option value='publishers'>publishers</option>");

这是一个附加到选择中间的小提琴:http: //jsfiddle.net/E3wpg/

于 2013-03-13T13:20:15.103 回答