eozzy
eozzy

Reputation: 68680

onClick for select menu?

the .click() event doesn't seem to work on select, please see: http://jsfiddle.net/fMTzD/

Even before the options are shown, I need the jQuery click function to do something. Is is possible? I don't mind even if the options are not shown at all.

Thanks

Upvotes: 0

Views: 1452

Answers (3)

Craig
Craig

Reputation: 7076

Another option is wrapping the select in a span and using it's click event:

Markup:

<span id="use-this">
    <select>
    </select>
</span>

jQuery:

$("#use-this").click(function(){
    alert("Select box was clicked");
});

I'd still like to know the reason behind select click event not triggering

Upvotes: 0

Treffynnon
Treffynnon

Reputation: 21553

I would use onFocus instead (although onMouseUp and onMouseDown are suitable alternatives):

$("select, button").focus(function () { 
    $(this).hide(); 
});

See my updates to your jsfiddle.

You cannot use onChange as that is triggered after the user chooses an option from the dropdown.

Upvotes: 2

naiquevin
naiquevin

Reputation: 7796

mouseup works too..

check here -

http://jsfiddle.net/fMTzD/4/

Upvotes: 0

Related Questions