Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Jquery ui selectable problem

Posted on 2015-02-17
4
Medium Priority
?
86 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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

I have answered several questions lately that were solved utilizing the power of jQuery's AJAX functions, so I thought I would write an article demonstrating the ease of use. Why should I use jQuery as opposed to regular JavaScript? Now I know…
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 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)
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

783 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