How to write below statement
if ($('#SelectedItems option[value=' + optionData.Value + ']').length === 0) ;
using the variable
var selectedItems = $('#SelectedItems');
//Something like this but not exactly
if ($(**selectedItems** + "option[value=' + optionData.Value + ']").length === 0) ;
I think you want this
This will select all the descendants of the elements in
selectedItemswhich match the selector"option[value='" + optionData.Value + "']".