i am trying to trigger an event on an option from a dropdown menu. for example:
<select id="select1">
<option id="1">1</option>
<option id="2">1</option>
</select>
i used an example on http://api.jquerymobile.com/taphold/ and appended the event to the option with id=1:
$( "#1" ).bind( "taphold", tapholdHandler );
to test the functionality, the tapholdHandler was just a simple alert. but did not work.
also, i tried to use the
jQuery( "#1" ).on( "tap", function( event ) {alert('works!');} )
but without success. however, i found out that it is possible to append this to the select element, but then it works for all the option elements within the select tag. how can i trigger a longclick/taphold event on a single option element? what i would like to do is to be able to longclick (hold the click) on a desired item and show a dialog which offers to delete the item from the list.
your selector is wrong
$('#1')
will select an element with id=1change your code to
$( "#1" ).bind( "taphold", tapholdHandler );
You cannot bind events to
<option>
elements with any real precision. You can however as stated elsewhere bind to thechange
event of the select menu in this case