How to put your cursor in the input tab
in Google, I put the code document.querySelector('[aria-label="Search"]').select();
How to put your cursor in the input tab in console log to see if the input tab of google gets selected. I confirmed that I correctly called the input tab but the console log just said undefined
How to put your cursor in the input tab with javascript. If it can't be javascript, please still share how to put your cursor in the input tab
javascript jquery
add a comment |
in Google, I put the code document.querySelector('[aria-label="Search"]').select();
How to put your cursor in the input tab in console log to see if the input tab of google gets selected. I confirmed that I correctly called the input tab but the console log just said undefined
How to put your cursor in the input tab with javascript. If it can't be javascript, please still share how to put your cursor in the input tab
javascript jquery
Possible duplicate of how to set cursor to input box in javascript?
– Jack Bashford
Nov 23 '18 at 21:37
I'm not sure what you are trying to do. Are you trying toconsole.log
the value of an input? Loggingdocument.querySelector('[aria-label="Search"]').select();
should log undefined because it doesn't have a return value.
– Katie.Sun
Nov 23 '18 at 21:39
add a comment |
in Google, I put the code document.querySelector('[aria-label="Search"]').select();
How to put your cursor in the input tab in console log to see if the input tab of google gets selected. I confirmed that I correctly called the input tab but the console log just said undefined
How to put your cursor in the input tab with javascript. If it can't be javascript, please still share how to put your cursor in the input tab
javascript jquery
in Google, I put the code document.querySelector('[aria-label="Search"]').select();
How to put your cursor in the input tab in console log to see if the input tab of google gets selected. I confirmed that I correctly called the input tab but the console log just said undefined
How to put your cursor in the input tab with javascript. If it can't be javascript, please still share how to put your cursor in the input tab
javascript jquery
javascript jquery
asked Nov 23 '18 at 21:34
The Bomb SquadThe Bomb Squad
305
305
Possible duplicate of how to set cursor to input box in javascript?
– Jack Bashford
Nov 23 '18 at 21:37
I'm not sure what you are trying to do. Are you trying toconsole.log
the value of an input? Loggingdocument.querySelector('[aria-label="Search"]').select();
should log undefined because it doesn't have a return value.
– Katie.Sun
Nov 23 '18 at 21:39
add a comment |
Possible duplicate of how to set cursor to input box in javascript?
– Jack Bashford
Nov 23 '18 at 21:37
I'm not sure what you are trying to do. Are you trying toconsole.log
the value of an input? Loggingdocument.querySelector('[aria-label="Search"]').select();
should log undefined because it doesn't have a return value.
– Katie.Sun
Nov 23 '18 at 21:39
Possible duplicate of how to set cursor to input box in javascript?
– Jack Bashford
Nov 23 '18 at 21:37
Possible duplicate of how to set cursor to input box in javascript?
– Jack Bashford
Nov 23 '18 at 21:37
I'm not sure what you are trying to do. Are you trying to
console.log
the value of an input? Logging document.querySelector('[aria-label="Search"]').select();
should log undefined because it doesn't have a return value.– Katie.Sun
Nov 23 '18 at 21:39
I'm not sure what you are trying to do. Are you trying to
console.log
the value of an input? Logging document.querySelector('[aria-label="Search"]').select();
should log undefined because it doesn't have a return value.– Katie.Sun
Nov 23 '18 at 21:39
add a comment |
1 Answer
1
active
oldest
votes
The code you have is correct. There are really two parts to your question:
Why does the console show undefined
after running .select()
?
To make sense of the undefined
, it's important to understand how the console works. When you enter an expression in the console, it runs it using eval
and displays the result. For example:
1 + 3
evaluates to4
var a = 1 + 3
evaluates toundefined
, even though a variable was defined
alert("hello")
evaluates toundefined
, even though an alert was displayed
In your example, HTMLInputElement.select()
doesn't return anything, so the console simply displays undefined
. With that being said, the code did in fact run. You can verify this by displaying an alert
using the console.
(If you're interested in the specifics of how the console decides what to display as the result of an expression, I'd take a look at this answer.)
Why doesn't the search field focus when running .select()
using the console?
For this part of your question, I'd recommend experimenting with the source of a page you control. Notice that if you setup a button to call .select()
on a text field, the field will focus. If you run that same code using the console, the field won't focus.
While I'm not sure of the specifics, it seems this is because the developer tools refuse to lose focus without the user specifically clicking a different element or closing them. If you instead wrap your expression in a timeout and change your focus before the timeout executes, your code works as expected.
You can verify this on both your page and Google's by doing the following:
Use the console to run:
setTimeout(() => document.querySelector('[aria-label="Search"]').select(), 2000)
Quickly click the background of the page to resign focus of the developer tools.
- Observe that the field focuses when the timeout executes.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53453172%2fhow-to-put-your-cursor-in-the-input-tab%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The code you have is correct. There are really two parts to your question:
Why does the console show undefined
after running .select()
?
To make sense of the undefined
, it's important to understand how the console works. When you enter an expression in the console, it runs it using eval
and displays the result. For example:
1 + 3
evaluates to4
var a = 1 + 3
evaluates toundefined
, even though a variable was defined
alert("hello")
evaluates toundefined
, even though an alert was displayed
In your example, HTMLInputElement.select()
doesn't return anything, so the console simply displays undefined
. With that being said, the code did in fact run. You can verify this by displaying an alert
using the console.
(If you're interested in the specifics of how the console decides what to display as the result of an expression, I'd take a look at this answer.)
Why doesn't the search field focus when running .select()
using the console?
For this part of your question, I'd recommend experimenting with the source of a page you control. Notice that if you setup a button to call .select()
on a text field, the field will focus. If you run that same code using the console, the field won't focus.
While I'm not sure of the specifics, it seems this is because the developer tools refuse to lose focus without the user specifically clicking a different element or closing them. If you instead wrap your expression in a timeout and change your focus before the timeout executes, your code works as expected.
You can verify this on both your page and Google's by doing the following:
Use the console to run:
setTimeout(() => document.querySelector('[aria-label="Search"]').select(), 2000)
Quickly click the background of the page to resign focus of the developer tools.
- Observe that the field focuses when the timeout executes.
add a comment |
The code you have is correct. There are really two parts to your question:
Why does the console show undefined
after running .select()
?
To make sense of the undefined
, it's important to understand how the console works. When you enter an expression in the console, it runs it using eval
and displays the result. For example:
1 + 3
evaluates to4
var a = 1 + 3
evaluates toundefined
, even though a variable was defined
alert("hello")
evaluates toundefined
, even though an alert was displayed
In your example, HTMLInputElement.select()
doesn't return anything, so the console simply displays undefined
. With that being said, the code did in fact run. You can verify this by displaying an alert
using the console.
(If you're interested in the specifics of how the console decides what to display as the result of an expression, I'd take a look at this answer.)
Why doesn't the search field focus when running .select()
using the console?
For this part of your question, I'd recommend experimenting with the source of a page you control. Notice that if you setup a button to call .select()
on a text field, the field will focus. If you run that same code using the console, the field won't focus.
While I'm not sure of the specifics, it seems this is because the developer tools refuse to lose focus without the user specifically clicking a different element or closing them. If you instead wrap your expression in a timeout and change your focus before the timeout executes, your code works as expected.
You can verify this on both your page and Google's by doing the following:
Use the console to run:
setTimeout(() => document.querySelector('[aria-label="Search"]').select(), 2000)
Quickly click the background of the page to resign focus of the developer tools.
- Observe that the field focuses when the timeout executes.
add a comment |
The code you have is correct. There are really two parts to your question:
Why does the console show undefined
after running .select()
?
To make sense of the undefined
, it's important to understand how the console works. When you enter an expression in the console, it runs it using eval
and displays the result. For example:
1 + 3
evaluates to4
var a = 1 + 3
evaluates toundefined
, even though a variable was defined
alert("hello")
evaluates toundefined
, even though an alert was displayed
In your example, HTMLInputElement.select()
doesn't return anything, so the console simply displays undefined
. With that being said, the code did in fact run. You can verify this by displaying an alert
using the console.
(If you're interested in the specifics of how the console decides what to display as the result of an expression, I'd take a look at this answer.)
Why doesn't the search field focus when running .select()
using the console?
For this part of your question, I'd recommend experimenting with the source of a page you control. Notice that if you setup a button to call .select()
on a text field, the field will focus. If you run that same code using the console, the field won't focus.
While I'm not sure of the specifics, it seems this is because the developer tools refuse to lose focus without the user specifically clicking a different element or closing them. If you instead wrap your expression in a timeout and change your focus before the timeout executes, your code works as expected.
You can verify this on both your page and Google's by doing the following:
Use the console to run:
setTimeout(() => document.querySelector('[aria-label="Search"]').select(), 2000)
Quickly click the background of the page to resign focus of the developer tools.
- Observe that the field focuses when the timeout executes.
The code you have is correct. There are really two parts to your question:
Why does the console show undefined
after running .select()
?
To make sense of the undefined
, it's important to understand how the console works. When you enter an expression in the console, it runs it using eval
and displays the result. For example:
1 + 3
evaluates to4
var a = 1 + 3
evaluates toundefined
, even though a variable was defined
alert("hello")
evaluates toundefined
, even though an alert was displayed
In your example, HTMLInputElement.select()
doesn't return anything, so the console simply displays undefined
. With that being said, the code did in fact run. You can verify this by displaying an alert
using the console.
(If you're interested in the specifics of how the console decides what to display as the result of an expression, I'd take a look at this answer.)
Why doesn't the search field focus when running .select()
using the console?
For this part of your question, I'd recommend experimenting with the source of a page you control. Notice that if you setup a button to call .select()
on a text field, the field will focus. If you run that same code using the console, the field won't focus.
While I'm not sure of the specifics, it seems this is because the developer tools refuse to lose focus without the user specifically clicking a different element or closing them. If you instead wrap your expression in a timeout and change your focus before the timeout executes, your code works as expected.
You can verify this on both your page and Google's by doing the following:
Use the console to run:
setTimeout(() => document.querySelector('[aria-label="Search"]').select(), 2000)
Quickly click the background of the page to resign focus of the developer tools.
- Observe that the field focuses when the timeout executes.
edited Nov 24 '18 at 0:54
answered Nov 24 '18 at 0:38
Ryan PendletonRyan Pendleton
2,0361328
2,0361328
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53453172%2fhow-to-put-your-cursor-in-the-input-tab%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Possible duplicate of how to set cursor to input box in javascript?
– Jack Bashford
Nov 23 '18 at 21:37
I'm not sure what you are trying to do. Are you trying to
console.log
the value of an input? Loggingdocument.querySelector('[aria-label="Search"]').select();
should log undefined because it doesn't have a return value.– Katie.Sun
Nov 23 '18 at 21:39