Solved

Jquery ui selectable problem

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

What is a Denial of Service (DoS)?

A DoS is a malicious attempt to prevent the normal operation of a computer system. You may frequently see the terms 'DDoS' (Distributed Denial of Service) and 'DoS' used interchangeably, but there are some subtle differences.

Question has a verified solution.

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

Hi all! Recently there was EE question and the person wanted to have a multi-column textbox <div> selection, so as a first step to answer I provided a link but that was not complete with JavaScript selection, but had a good style sheet. So as a ques…
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)

623 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