views:

395

answers:

3

Hello, 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?

+1  A: 

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.

Daniel Schaffer
Could you please give me name of any function or something I should look for?
Mike
+1  A: 

try the change event example here

Yassir
+1  A: 

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"&gt;&lt;/script&gt;  
    <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.

Sbm007