Solved

Jquery ui selectable problem

Posted on 2015-02-17
4
83 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
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)

751 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