最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Loop through all elements in the div and set all elements tabindex to -1 - Stack Overflow

programmeradmin1浏览0评论

How can I loop through all elements in the div and set all elements tabindex to -1?

$('.somediv').each(function() {

});

How can I loop through all elements in the div and set all elements tabindex to -1?

$('.somediv').each(function() {

});
Share Improve this question edited Feb 26, 2016 at 9:28 Rory McCrossan 338k41 gold badges320 silver badges351 bronze badges asked Feb 26, 2016 at 9:24 Arun BertilArun Bertil 4,6484 gold badges36 silver badges59 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 7

You can try this:

$('.somediv *').attr("tabindex","-1");

Enjoy coding!

You can use .somediv * selector like following.

$('.somediv *').attr("tabindex", "-1");

Try to use .attr() at this context,

$('.somediv').attr("tabindex","-1");

And there is no need to iterate over all the elements.

If you want to set tabindex to all the children/descendants of .somediv then just change your selector.

$('.somediv > *').attr("tabindex","-1"); //children
$('.somediv *').attr("tabindex","-1");  //descendants

and also if you want to set tabindex to .somediv then call .addBack() before calling the .attr()

发布评论

评论列表(0)

  1. 暂无评论