4

I need to select the text of dropdown list in which id ends with string SelectId

if the id is a fixed one like fixedid, it can be achieved by

var val = $('#fixedid :selected').text();

But, in my case, I know only some end text of that id and that is SelectId

I have tried below code but it failed

$('[id$="SelectId"]').text()

How I can achieve this?

NeoCoder
  • 101
  • 1
  • 8

2 Answers2

2

You need to get the selected option within it for getting text content of selected option.

$('[id$="SelectId"] :selected').text()
//-----------------^^^^^^^^^^^-------
Pranav C Balan
  • 113,687
  • 23
  • 165
  • 188
2

This should work to get the option.

$("select[id$='SelectId'] option:selected").text()
Sean T
  • 2,414
  • 2
  • 17
  • 23