javascript - is(':visible') not working -
hey guys new jquery , going throught modal.js code , found below code:
$target.one('show.bs.modal', function (showevent) { if (showevent.isdefaultprevented()) return // register focus restorer if modal shown $target.one('hidden.bs.modal', function () { $this.is(':visible') && $this.trigger('focus') }) })
i tried understand above code , made fiddle.
now if see if conditional in code :
if ($this.is(':visible')) { $('input').trigger('focus'); console.log($this + ' ' + 'is visible'); } else { console.log($this + ' ' + 'invisible'); }
now if have following display rule i.e.
input { display:none; }
the if condition still passes , thats 1st difficulty . why if condition pass ??
my secound difficulty line inside if condition i.e.
$this.trigger('focus');
now though if condition passes input does't focus . why ??
thank .
i've made minor chances code, , seems work me:
$(document).ready(function () { $target = $('input'); $target.trigger('focus'); $target.one('show.bs.modal', function (showevent) { $this = $(this); console.log($this); if ($this.is(':visible')) { $this.focus(); } else { console.log($this + ' ' + 'invisible'); } $target.one('hidden.bs.modal', function () { $this.is(':visible') && $this.trigger('focus') }); }); $target.trigger('show.bs.modal'); });
http://jsfiddle.net/v36zoy1g/2/
to focus element, don't need fancy code. .focus()
function job you! , actually, think that's it, can't remember else changed honest. :p
Comments
Post a Comment