Wizard of Oz
Wizard of Oz

Reputation: 175

JQuery: How to disable mouse over scrolling on all <select> elements on a page

the code below doesn't seem to be working. What am I missing here?

<script type="text/javascript" language="javascript">
    //disables scrolling on mouse over of <select> elements
    $(document).ready(function() {
        $('select').each(function() {
            $(this).attr('onmousewheel', 'return false;');
        });
    });
</script>

Upvotes: 0

Views: 1958

Answers (3)

chanaka777
chanaka777

Reputation: 389

onmousewheel is not really a attribute of SELECT HTML Element. See http://www.w3schools.com/tags/tag_select.asp

You are trying to set Mouse event. http://www.w3schools.com/tags/ref_eventattributes.asp

You can achieve this in the way MISJHA pointed.

Upvotes: 1

Manish Kumar
Manish Kumar

Reputation: 10502

try removeAttr. It removes the attached DOM attribute

Upvotes: 0

MISJHA
MISJHA

Reputation: 1008

You can try this:

<script type="text/javascript" language="javascript">
    //disables scrolling on mouse over of <select> elements
    $(document).ready(function() {
        $('select').each(function() {
            $(this).on('mousewheel', function(){
                return false;
            });
        });
    });
</script>

Upvotes: 2

Related Questions