Below is sample jQuery code
$('#HomeCity option:selected').text()
how do change HomeCity to optionElement[key] which from foreach function?
I did
$(" '#' + optionElement[key] option:selected ").text()
but not working.
Currently the code you mentioned wont be working because you have wraped it inside double quotes. So as per your code
$(" '#' + optionElement[key] option:selected ").text()
'#' + optionElement[key] option:selected is one string that jQuery is searching for and it doesnt exist in your page.
What you should be doing to make it dynamic is
$("#"+optionElement[key]+"option:selected").text()
This way your optionElement[key] is dynamic which will be changed as per the option selected.
Hope this be of some help.
Happy Learning