Solved

Jquery ui selectable problem

Posted on 2015-02-17
4
80 Views
Last Modified: 2015-02-17
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?
0
Comment
Question by:Panos
  • 2
4 Comments
 
LVL 8

Expert Comment

by:Ahmed Merghani
ID: 40614104
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
 
LVL 2

Author Comment

by:Panos
ID: 40614233
Hi.
I get this TypeError: ui.attr is not a function
0
 
LVL 44

Accepted Solution

by:
Rainer Jeschor earned 500 total points
ID: 40614235
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
 
LVL 2

Author Comment

by:Panos
ID: 40614270
Thank you very much Rainer Jeschor
It is working.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Got endorsements from your clients?  Great!  There is almost nothing better than word-of-mouth advertising.  But how can you do that on the internet?  Sure you can make a page for endorsement quotations and list them all, but who is …
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question