1

On performing inspect element on google.com input, I get:

<input class="gsfi" id="lst-ib" maxlength="2048" name="q" autocomplete="off" title="Search" type="text" value="" aria-label="Search" aria-haspopup="true" role="combobox" aria-autocomplete="both" dir="ltr" spellcheck="false" style="border: none; padding: 0px; margin: 0px; height: auto; width: 100%; background: url(&quot;data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw%3D%3D&quot;) transparent; position: absolute; z-index: 6; left: 0px; outline: none;">

Now if I do: $("#lst-ib"), I get input object as expected. But if I do: $("#lst-ib").val("hello world!"), I get an error:

Uncaught TypeError: $(...).val is not a function(…)

Same thing is happening with Bing.com. Can someone explain why is it happening and how can I search on these website by using Javascript or Jquery.

dasfdsa
  • 7,102
  • 8
  • 51
  • 93
  • 1
    $ doesn't mean is jquery. it can be just a namespace for some selector function writen by their internal programmer. – Simon Nov 24 '16 at 07:01

3 Answers3

1

The reason is google doesn't use jQuery, so you can't use jQuery functions there.

try this

//change the input
document.getElementById("lst-ib").value = "What you want to find";
//submit form
document.getElementById("tsf").submit();

It will change the search input as you expected.

Hoang Do
  • 325
  • 1
  • 14
0

The object that is being retrieved with $("#lst-ib") is not your usual jquery object. Google must be using a customized JS library. However, you can change the value of the input by this:

$("#lst-ib").value = 'new value';
owaisafaq
  • 523
  • 4
  • 7
0

$ dosen't always mean its jQuery. It can be used as a shorthand for any library.

If you want to use $ as Jquery only always pass jQuery as object and then use.. like

 (function ($) { 
   //jQuery Code. 
 })(jQuery);
Atul Sharma
  • 9,397
  • 10
  • 38
  • 65