user3248186
user3248186

Reputation: 1558

How to add action event on a variable?

I'm using a variable say component to iterate through a menu list in jQuery, where each item is assigned to component while iterating.

var component = $('select#load option');

where all choices are enclosed like this under `id="load":

<option>choice</option>

How can I attach an event like dblclick to all of these choices in the list, so that if I double click on one of the choices in the menu, it opens. I did this, but it didn't work:

component.dblclick(function(){
....
});

Upvotes: 1

Views: 91

Answers (1)

alexqoliveira
alexqoliveira

Reputation: 379

What you try to do is something like this?

$(function(){
    
  var $opt = $('select#test option');
    
  $opt.on('dblclick',function(){
    
      alert($(this).val());
    
  });
  
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>


<select id='test'size='3'>
  <option>1</option>
  <option>2</option>
  <option>3</option>
</select>

Upvotes: 1

Related Questions