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
3 Answers
Reset to default 7You 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()