I have a php generated list whose list items are selectable using jquery selectable widget. The list for all intents and purposes is:
The parameter ui
has a property called selected
which is a reference to the selected dom element, you can call innerHTML
on that element.
Your code $('.ui-selected').innerHTML
tries to return the innerHTML
property of a jQuery wrapper element for a dom element with class ui-selected
$(function () {
$("#select-image").selectable({
selected: function (event, ui) {
var $variable = ui.selected.innerHTML; // or $(ui.selected).html()
console.log($variable);
}
});
});
Demo: Fiddle
Use .val()
instead of .innerHTML
for getting value of selected option
Use .text()
for getting text of selected option
Thanks for correcting :)
Try
.text() or .html() instead of .innerHTML
$(function() {
$("#select-image").selectable({
selected: function( event, ui ) {
var $variable = $('.ui-selected').html();
console.log($variable);
}
});
});
or
$(function() {
$("#select-image").selectable({
selected: function( event, ui ) {
var $variable = $('.ui-selected').text();
console.log($variable);
}
});
});
or
$(function() {
$("#select-image").selectable({
selected: function( event, ui ) {
var $variable = $('.ui-selected').val();
console.log($variable);
}
});
});