javascript - JQuery - Selecting by class doesn't work -


i new , i've started writing things myself, , have small problem, selecting class doesn't work me. use tampermonkey write search phrase google search (www.gooogle.com). getting element id works fine:

$("#lst-ib").val("something"); 

but getting class doesn't work:

$(".gsfi").val("something"); 

i tried adding code make run after dom ready, looks this:

$(document).ready(function() {     $(".gsfi").val("something"); }); 

why doesn't work?

from question there should not chance of issues. if set value of element should happen. if thinking setting value of element change text of div, wrong. setting value of html element not change content of div. need set text of div. have attached sample code snippet setting value of element , changing text of element.

<!doctype html>  <html>  <head>  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>  <script>    $(document).ready(function(){      $(".test").val("value1");      $("#test").val("value2");  });    function alertvalues(){  	console.log($(".test").val());      console.log($("#test").val());  }    function changetext(){  	$(".test").text("changed content 1");      $("#test").text("changed content 2");  }  </script>  </head>  <body>    <div class="test">sample text 1</div>  <div id="test">sample text 2</div>  <button onclick="alertvalues()">log values</button>  <button onclick="changetext()">change text</button>    </body>  </html>


Comments

Popular posts from this blog

javascript - React Maximum Callstack when adding component -

javascript - Uncaught FirebaseError: Messaging: This method is available in a Window context -

correlation - Autocorrelation in Matlab WITHOUT xcorr -