Jquery ui selectable problem

Hello experts
I need help with my code.
I'm using jquery 1.7.1 and jquery ui 1.8.18
I want to add an event on selecting but i don't get the right value.
I have a list like:
<ul class="ui-selectable">
<li id="partid_0" class="partselect ui-widget-content ui-selectee">All</li>
<li id ="partid_1" class="partselect ui-widget-content ui-selectee">test 1</li>
<li id ="partid_2" class="partselect ui-widget-content ui-selectee">test 2</li>
</ul>

and script:
$( ".ui-selectable" ).selectable({
      selected: function( event, ui ) {
      var target = $(this).attr("id");
        var i = target.split("_");alert(i)
        }
      });
I get i undefined
(i need the id value from the selected list but i don't get it. I did not understand the api documentation to fix this)
Any help?
LVL 2
PanosAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Rainer JeschorConnect With a Mentor Commented:
Hi,
this is working:
var i = ui.selected.id.split("_")[1];

Open in new window

Please see the sample based on your input:
http://jsfiddle.net/EE_RainerJ/nh224f4g/

HTH
Rainer
0
 
Ahmed MerghaniSoftware EngineerCommented:
Hi,

Try to change this line:
var target = $(this).attr("id");

Open in new window

to:
var target = ui.attr("id");

Open in new window

0
 
PanosAuthor Commented:
Hi.
I get this TypeError: ui.attr is not a function
0
 
PanosAuthor Commented:
Thank you very much Rainer Jeschor
It is working.
0
All Courses

From novice to tech pro — start learning today.