2

How can I trigger the select-event inside some jquery code?

edit:
I'm using jquery-ui selectable. The selectable items are <"li"> inside an <"ol"> list.
(documentation: http://jqueryui.com/demos/selectable/)

I cant trigger it by "click" nor "selecting" nor "select" ...

Frank M.
  • 171
  • 3
  • 13
  • http://stackoverflow.com/questions/3140017/jquery-ui-how-to-programatically-select-selectables/4863890#4863890 was working for me. – Tobias Jul 20 '11 at 09:44

3 Answers3

0
$("#selectable2").selectable({
 filter: "div",
 selecting: function(ev, ui) {
 $(ui.selecting).text('selecting');
 },
 selected: function(ev, ui) {
 $(ui.selected).text('selected');
 },
 unselecting: function(ev, ui) {
 $(ui.unselecting).text('unselecting');
 },
 unselected: function(ev, ui) {
 $(ui.unselected).text('unselected');
 }
 });

DEMO

0

Try:

$('#elem_id').select();

http://docs.jquery.com/Events/select

Alex Sexton
  • 10,401
  • 2
  • 29
  • 41
0

Ok, now that you've edited, I'll try this one as well:

This isn't an exact replica of a select, but depending on your situation, could do what you need.

var desired_option_index = 1;
$('ol#myOptions li').eq(desired_option_index).addClass('ui-selected');

If you have callback functions that are important, you could call those explicitly right afterward, or before, depending on the event.

Alex Sexton
  • 10,401
  • 2
  • 29
  • 41