Friday, September 22, 2017

jQuery .focus() and .blur() not working in Chrome or Safari for checkbox and radio


jquery focusout does not works in chrome and safari for checkbox and radio elements.

example:
<input type='checkbox' name='ch1' id='ch1' />

<script type='text/javascript'>
$(document).ready(function(){
$(document).on('focusout','#ch1', function(){
alert('Focus Out');
});

});
</script>

To fix this, try to setup focus for checkbox when click on it

<script type='text/javascript'>
$(document).ready(function(){

$(document).on('click','#ch1', function(){ // set focus for element on click for chrome and safari
$(this).trigger("focus");
});

$(document).on('focusout','#ch1', function(){
alert('Focus Out');
});

});
</script>

No comments:

Post a Comment

Restore xampp database from backup

steps: stop mysql xampp 1 - create some backup folder "data_1"  2 - from your current xampp/mysql/data folder move core folders an...