{"id":1086,"date":"2018-04-10T10:04:58","date_gmt":"2018-04-10T09:04:58","guid":{"rendered":"https:\/\/solidt.eu\/site\/?p=1086"},"modified":"2018-04-10T10:04:58","modified_gmt":"2018-04-10T09:04:58","slug":"jquery-enable-tab-shift-tab-only-in-modal-dialog-element","status":"publish","type":"post","link":"https:\/\/solidt.eu\/site\/jquery-enable-tab-shift-tab-only-in-modal-dialog-element\/","title":{"rendered":"jQuery: Enable Tab + Shift-tab only in modal dialog element"},"content":{"rendered":"<pre class=\"lang:default decode:true  \">var dialog = $('.modal');\r\ndialog.on('keydown', function(e) {\r\n\tvar tab = 9;\r\n\tif (e.which === tab) {\r\n\t\te.preventDefault();\r\n\t\tvar inputs = $('input, a, button', dialog).filter(':visible');\r\n\r\n\t\tvar ci = 0;\r\n\t\tinputs.each(function(i) {\r\n\t\t\tif ($(this)[0] == document.activeElement) {\r\n\t\t\t\tci = i;\r\n\t\t\t}\r\n\t\t});\t\t\r\n\t\tvar step = 1;\r\n\t\tif (e.shiftKey) step = -1;\r\n\t\tci += step;\r\n\t\tif (ci &lt; 0) ci += inputs.length;\r\n\t\tinputs[ci % inputs.length].focus();\r\n\t}\r\n});<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>var dialog = $(&#8216;.modal&#8217;); dialog.on(&#8216;keydown&#8217;, function(e) { var tab = 9; if (e.which === tab) { e.preventDefault(); var inputs = $(&#8216;input, a, button&#8217;, dialog).filter(&#8216;:visible&#8217;); var ci = 0; inputs.each(function(i) { if ($(this)[0] == document.activeElement) { ci = i; } }); var step = 1; if (e.shiftKey) step = -1; ci += step; if (ci &lt; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[5],"tags":[],"class_list":["post-1086","post","type-post","status-publish","format-standard","hentry","category-javascript"],"_links":{"self":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/1086","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/comments?post=1086"}],"version-history":[{"count":1,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/1086\/revisions"}],"predecessor-version":[{"id":1087,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/1086\/revisions\/1087"}],"wp:attachment":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/media?parent=1086"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/categories?post=1086"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/tags?post=1086"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}