-1

I have a Jquery UI selectmenu object which I have generated dynamically from a database.

I need to get the selected text from it, if it wasn't an Jqueryu UI object I could use this at onChange event like that:

$('#l1').change(function() {
    var selectedText= $('#l1 option:selected').text();
....

How could I get the same value for Jquery UI object? I mention that I can't rely on .val() property because all are 0. I did try this

var selectedText = $(this).find(':selected').text();

without success.

1
  • Why the downvote? Would be useful to know otherwise .... I could imagine anything. Commented Dec 2, 2018 at 21:00

1 Answer 1

0

Find out!

It's about how I relate to the on change event.

When I use Jquery UI I have to use:

$('#l1').selectmenu({change: function (event, data) {

instead of:

$('#l1').change(function() {

Now I will try to find why is it that way?

Sign up to request clarification or add additional context in comments.

1 Comment

That because selectmenu creates new DOM elements to "replace" the original <select>, which is hidden. So it is no longer <select> and <option> that user see... But a bunch of <ul>, <li> and <div> elements. --- And as you found out by yourself (+1 for that), the events are handled from within the selectmenu instance.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.