my code is error td.textContent.focus is not a function
my function is like this
var tds = document.querySelectorAll('td');
[].forEach.call(tds, function(td) {
if (td.textContent == ' Survey (Notes)') {
td.textContent.focus();
}
});
when i use alert below condition of text.context is show a result
but when i’m using focus it’s show an error
i want to focus on that result when the page is loaded
thanks
2
Answers
use td.focus(),even td can not be focused
By default,
td
elements are not focusable. You need to add thetabindex
attribute to make it focusable.Focus on the
td
element, nottextContent
: Once thetd
element is made focusable, you can call the focus method on the element itself.