Manoj Nayak
Manoj Nayak

Reputation: 2509

How to get the selected text of dynamic dropdown in jquery

I am able to get the selected value of a dynamic dropdown using the below code

    $("span[id*="+ orgId +"]")[0].innerHTML=$("'input[id$=" + comanyDropDown+ "]:'selected").val();

I want the retriev the selcted text for which i used

$("span[id*="+ orgId +"]")[0].innerHTML=$("'input[id$=" + comanyDropDown+ "]:'selected").text();

But it will retrieve all the items of the dropdown.

I tried with

$("span[id*="+ orgId +"]")[0].innerHTML=$("'input[id$=" + comanyDropDown+ "]:option:'selected").text();

How to get the selected text of dynamic dropdown.

Upvotes: 0

Views: 1203

Answers (1)

Ram
Ram

Reputation: 144659

Your selector is wrong. There is no :option selector, also you trying to filter an input element which is an option, surely your selector doesn't find such element. Try the following:

$("span[id*="+ orgId +"]")
      .html( $("option[id$=" + comanyTextBox + "]:selected").text() );

Upvotes: 1

Related Questions