thinker thinker - 1 month ago 7
Javascript Question

How can I get data from the selected element?

A page contains html

<ol id="selectable">
<li class="ui-widget-content word">I've</li>
<li class="ui-widget-content word">got</li>
<li class="ui-widget-content word">a</li>
<li class="ui-widget-content word">job</li>
</ol>


I try to get data from li element

$(function() {
$("#selectable").selectable({
stop : function() {
var result = $("#select-result");
$(".ui-selected", this).each(function() {
//getting data from an element
var value = $("#selectable li").data(this);
console.log("value"+value); //this outputs to `value[object Object]`
});
}
});

});


How can I get data from the selected element?

Answer

You can do this:

function getDATA(){    
    var data;
    $("#selectable li").each(function() {
         data += $(this).text();
    })

    console.log(data);
}