click event on options doesn't work in Safari


Large size

I will recreate my problem with a very simple code (see below):

<html>
<head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
    <select class="a">
        <option class="b" value="opt1">opt1</option>
        <option class="b" value="opt2">opt2</option>
        <option class="b" value="opt3">opt3</option>
        <option class="b" value="opt4">opt4</option>
    </select>

    <script>
    $('.b').click(function(){
        alert("hi");
    });

    </script>
</body>

I want if an option (in the dropdown) is clicked, an alert message will be displayed. In Firefox this does happen fine, but in Safari it doesn't work. Can someone help me get this working in Safari?

people

There are some known workarounds:

  • add cursor:pointerto <option>your
  • replace .click(function(){})with.on('click touchstart', function(){})

Another option (IMHO the correct one) is to use an event oninputon the parent <select>:

 $('select').on('input', function(){/* whatever */})

$('select').on('input', function(){
  console.log($(this).val())
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select>
  <option value=""> Select something </option>
  <option>1</option>
  <option>2</option>
  <option>3</option>
</select>

Related


click event on options doesn't work in Safari

Large size I will recreate my problem with a very simple code (see below): <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> </head> <body> <select class="a"> <option class="b" value="opt1">o

click event on options doesn't work in Safari

Large size I will recreate my problem with a very simple code (see below): <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> </head> <body> <select class="a"> <option class="b" value="opt1">o

Invoking input's click event doesn't work in Safari

super hornet I have an input, file type, with display:nonea button. When the button is clicked, the input event should fire. In IE, Chrome and Firefox it works but not in Safari! var elem=$('<input id="ajxAttachFiles" name="fileUpload" type="file" style="displ

Invoking input's click event doesn't work in Safari

super hornet I have an input, file type, with display:nonea button. When the button is clicked, the input event should fire. In IE, Chrome and Firefox it works but not in Safari! var elem=$('<input id="ajxAttachFiles" name="fileUpload" type="file" style="displ

Invoking input's click event doesn't work in Safari

super hornet I have an input, file type, with display:nonea button. When the button is clicked, the input event should fire. In IE, Chrome and Firefox it works but not in Safari! var elem=$('<input id="ajxAttachFiles" name="fileUpload" type="file" style="displ

Invoking input's click event doesn't work in Safari

super hornet I have an input, file type, with display:nonea button. When the button is clicked, the input event should fire. In IE, Chrome and Firefox it works but not in Safari! var elem=$('<input id="ajxAttachFiles" name="fileUpload" type="file" style="displ

click event click doesn't work

Alifur Islam History and homepage are working fine but 'ng-click="toggleMenu()"' is not working so please help me click event is ng-click="toggleMenu()"not working. Can someone help me out? my code is <ion-tab title="History" icon-off="ion-document" icon-on="i

click event click doesn't work

Alifur Islam History and homepage are working fine but 'ng-click="toggleMenu()"' is not working so please help me click event is ng-click="toggleMenu()"not working. Can someone help me out? my code is <ion-tab title="History" icon-off="ion-document" icon-on="i

click event click doesn't work

Alifur Islam History and homepage are working fine but 'ng-click="toggleMenu()"' is not working so please help me click event is ng-click="toggleMenu()"not working. Can someone help me out? my code is <ion-tab title="History" icon-off="ion-document" icon-on="i

jQuery click event doesn't seem to work

Akahne Saikyo I'm practicing making a simple calculator using jQuery, and I think the code itself is pretty simple, but no matter what I do, absolutely nothing happens, as if there's no js file linked to beging. Here is the jQuery code: function ud(n){

jQuery .off("click") event doesn't work

basic need help This has been bugging me for hours and still confused as to why it doesn't work... When I use table.off("click");it , it also unbinds the click event of the first child without id=multi. var table = $("table#datatable") var button = $(".generat

Not a selector, the on() click event doesn't work

Cesar Bielich i have my html <tr class="show_ticket_preview"> <td> <a class="ticket_preview_id">A Link</a> <p>Some other stuf</p> </td> </tr> I need to fire the click event on click, trnot when a is <a>clickedtr $(document).on('click

FloatingActionButton Click event doesn't work

George I have a floating action button in the following layout file activity_register: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"

Knockout click event doesn't work

Mike Wells I'm creating a weather page for myself (and possibly others in the future) and am having trouble with the button to show and hide weather alerts. You can check the page to see what I'm trying to do. (Sorry, I'm picking FL, but they have a lot of ale

Click event doesn't work in javascript

Soheil Alizadeh I will follow this article on Impredement CRUD operations with HTML5 and Javascript . This allows the data to be committed to local storage and saved. My problem is that there is no "delete and edit action" when clicking the "delete and edit" b

Onclick event doesn't work on first click

Vihar After the page loads, I need to click the button twice to trigger the onclick()function. After doing this, everything works as expected. Since I'm new to this web development field, I'd really appreciate a detailed explanation. Thank you in advance. var

jQuery click event doesn't work

mightyspaj3 I have this simple jQuery click event and for some reason it's not working. works, I can use this inside the $(document).ready(function() {});alert; however the actual click event doesn't work. Thanks in advance and please take it easy on me as I d

MathJax doesn't work in Jquery .click event

Glagas Incoming MathJaxJquery .clickevent doesn't work inside but outside that function. Run the code snippet to see the effect. $('#math').click(function(e){ e.preventDefault(); $("#result").html("$$ MathJax inside .click event doesn't work $$"); }); //outsid

jQuery Click event doesn't work on mobile

lkw3274 I'm trying to make the following JSFiddle work for tablet/mobile (eg "touch" and "click"). https://jsfiddle.net/lkw274/7zt1zL0g/87/ <div class="user-navigation"> <a class="mobile-menu-new" href=""><span></span>Menu</a> </div> $(document).ready

Click event doesn't work on dcmads

Germet Singh | I want to make an ajax call whenever someone clicks on a dcmads ad placed on my site. But I can't do it. I thought it was somehow because of event bubbling and catching, even trying to resolve it, but that didn't have any effect. HTML - <div cla

$(this) doesn't work in defined click event

Pawan Yekabot $(document).ready(() => { $(".tabs-item").click(() => { $(".tabs-item").removeClass("active"); $(this).addClass("active"); //This line is not at all working.. }); }); $(this)doesn't work at all. I've been trying different appro

"this" doesn't work in click event handler

network I have attached a click event handler to my ChartJS derived component like this: export default { extends: HorizontalBar, data() { return { my_data: [], options: { onClick: function(event, args) { //need to access

click event on jQuery doesn't work

Creep to death I have printed the echo with php of the input element and I need to get the click event id using jquery. Below is the code I am trying to get API.php (Echo elements to index.php using ajax): echo"<input type='submit' id='something' value='accept

Datatable click event on header doesn't work

Sagar Bagdev I put a checkbox in the header for selecting other checkboxes, but the click event doesn't work for the header. Javascript code $(document).ready(function () { $('#example').on('click','.checkAll', function () { alert("hi"); if ($(this).p

ToolStripMenuItem click event doesn't work

Axilleas DevAxe I tried to open the file dialog window by pressing the "Open" button ( ToolStripMenuItem) , but for some reason it didn't work (no errors, just not working). If I will write the exact same code in the method it works fine: toolStripDropDownButt

JQuery click() event listener doesn't work

it consolidates I'm trying to get a small project going, but I'm stuck at a very annoying thing. $(document).ready(function() { $("#search-button").click(console.log('hello')) }); As you can see, I'm targeting a search button using the id, and search-buttona

Click event on parent doesn't work on child

Lester Vargas I have some square divs on my website that display text and a large icon. I want a modal to appear when the user clicks on the div, but since the icon is an object, the modal appears when the user clicks on the div (just the div, not the icon). W

jQuery .off("click") event doesn't work

basic need help This has been bugging me for hours and still confused as to why it doesn't work... When I use table.off("click");it , it also unbinds the click event of the first child without id=multi. var table = $("table#datatable") var button = $(".generat

Click event doesn't work on tab

ask I have the following jsx code that doesn't work with mouseclicks: import React from 'react'; import Tabs from 'material-ui/lib/tabs/tabs'; import Tab from 'material-ui/lib/tabs/tab'; const Main = () => ( <div> <Tabs> <Tab label="Item One" >