0

I've got this code, that works in the latest version of firefox, opera and I'm not sure if in IE8, but it doesn't work in Google Chrome, Safari and ofc IE7 and 6.

The script I have is a bit more complicated, but the problem is in this:

<select>
<option class='gramaz_vyber'>1</option>
<option class='gramaz_vyber'>2</option>     
</select>

And the jQuery:

$('.gramaz_vyber').click(function() {
    $(this).hide();
});

As I wrote before, the code I have looks different, but I need to start a function after I click on the <option> and it only works in FF/Opera ... any idea how could I get around it?

3 Answers 3

1

It is funny indeed, it seems that you cannot use hide() on option elements in IE7 (not tested on IE8).

But the following code works:

<html>
<head></head>

<body>
    <select>
        <option>-</option>
        <option class="removable">1</option>
        <option class="removable">2</option>         
    </select>

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>  
    <script type="text/javascript">
        $(function() {
            $('select').change(function() {
                $(this).find('option.removable:selected').remove();
            });
        });
    </script>

</body>
</html>

The difference is that you are removing the object from DOM instead of simply hiding it.

Sign up to request clarification or add additional context in comments.

Comments

1

Off the top of my head, I don't think all browsers support click events for <option> elements.

You'll need to handle the change event for the parent <select> element.

1 Comment

Could you please give me name of any function or something I should look for?
1

try the change event example here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.