Unable to display selected value in jquery selectable

Unable to display selected value in jquery selectable

I want to display the selected item and only one item should be able to selected

i achieved the second but struggling for first, Help Plz!!!!!!


  1. <!DOCTYPE html>
  2. <html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  3.   <meta charset="UTF-8">
  4.   <title>jQuery single select</title>
  5.     <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>

  6.   <style type="text/css">
  7.     
  8. #feedback { font-size: 1.4em; }
  9. #selectable .selecting { background: #FECA40; }
  10. #selectable .selected { background: #F39814; color: white; }
  11. #selectable { list-style-type: none; margin: 0; padding: 0; width: 60%; }
  12. #selectable li { margin: 3px; padding: 0.4em; font-size: 1.4em; height: 18px; }
  13.   </style>
  14. <body>

  15. <ul id="selectable">
  16. <li>Item 1</li>
  17. <li>Item 2</li>
  18. <li>Item 3</li>
  19. <li>Item 4</li>
  20. <li>Item 5</li>

  21. </ul>
  22.   <p id="feedback">
  23. <span>You've selected:</span> <span id="select-result">none</span>.
  24. </p>

  25. <script>
  26. $("#selectable li").click(function() {
  27. $(this).addClass("selected").siblings().removeClass("selected");
  28. var result = $( "#select-result" ).empty();
  29. $( ".selected", this ).each(function() {
  30. var index = $( "#selectable li" ).index( this );
  31. result.append( " #" + ( 0 + 1 ) );
  32. });
  33. });
  34. </script>
  35. </body></html>