Solved

Jquery ui selectable problem

Posted on 2015-02-17
4
77 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

What is a Lightbox? A Lightbox is the effect you see when you click, for example, an image and the screen fades out and up pops the same image but in its full size dimensions. There are lots of Lightbox effects for jQuery. Problem is they are a…
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)

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now