How to select dropdown text whose id ends with some string in jQuery?

I need to select a dropdown text in which id ends with a string SelectId

if id is fixed as fixedidit can be reached with

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

But in my case, I know only some final text of this identifier, and this SelectId

I tried the code below but it failed

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

How can i achieve this?

+4
source share
2 answers

You need to get the selected option to get the text content of the selected option.

$('[id$="SelectId"] :selected').text()
//-----------------^^^^^^^^^^^-------
+2
source

This should work to get the option.

$("select[id$='SelectId'] option:selected").text()
+2
source

Source: https://habr.com/ru/post/1690854/


All Articles