jquery - How can I assign a tabindex value to all elements starting with a specific element? -
the next code snippet assigns tabindex
value elements on page starting first element on page. i'd same thing rather origin first element on page i'd begin specific element , loop through remaining elements.
edit additional requirement: i'd chose first element id attribute loop through rest.
$(function(){ var tabindex = 1; $('input,select').each(function() { if (this.type != "hidden") { var $input = $(this); $input.attr("tabindex", tabindex); tabindex++; } }); });
you can utilize :gt(n)
psedo selector. next assign tab index starting 10th element:
$(function(){ var tabindex = 1; $(':input:not([type=hidden])').filter('input,select').filter(':gt(8)').each(function() { var $input = $(this); $input.attr("tabindex", tabindex++); }); });
update
as id requirement, have loop through elements , elect alter meet requirement:
$(function(){ var tabindex = 1; $(':input:not([type=hidden])').filter('input,select').each(function() { if( $(this).is('#desired_id') || tabindex > 1 ) { var $input = $(this); $input.attr("tabindex", tabindex++); } }); });
jquery
No comments:
Post a Comment