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?

3

2 Answers 2

2

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

$('[id$="SelectId"] :selected').text() //-----------------^^^^^^^^^^^------- 
Sign up to request clarification or add additional context in comments.

Comments

2

This should work to get the option.

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

1 Comment

Anybody care to tell me what it wrong with this approach when down voting?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.