zgrizzly_7
zgrizzly_7

Reputation: 793

get the text of a selectable element inside a ordered list jquery

I have the following ordered list:

<ol class="list">
    <li id="1">one</li>
    <li id="2">two</li>
    <li id="3">three</li>
 </ol>

And I just want to get the text of the selectable li. I mean, when I click in one of the elements I want to get the text of this element. I tryed like this:

$(function() {
        $( ".list" ).selectable({
          stop: function() {
            $( ".ui-selected", this ).each(function() {
                 alert($(".list li").text());
            });
          }
        });
    });

But with this I just get the text of all <li> elements of the list and not the text of one selectable <li> Is there a solution for this?

Upvotes: 0

Views: 134

Answers (1)

Deepak Biswal
Deepak Biswal

Reputation: 4320

Here is the working fiddle.

JS

$(function() {
        $( ".list" ).selectable({
          stop: function() {
            $( ".ui-selected", this ).each(function() {
                 console.log($(this).text());
            });
          }
        });
    });

NOTE: Use $(this) instead of $(".list li").

Upvotes: 2

Related Questions