This is in reference to this SO answer. I am trying the same on web.whatsapp.com (chrome) for its input search field. Here is my code to do it:
document.getElementsByClassName("input input-search")[0].focus()
document.getElementsByClassName("input input-search")[0].select()
Above does not work from chrome console.
Also the jQuery code:
$(".input-search").focus()
does not work. What could be the reason that I don't see the cursor even after executing above methods?
document.querySelector(".input-search").focus();
works! and$(".input-search").focus();
provided you havejQuery
included. – lshettyl