Jquery: text input how to get

I am trying to get the value of text in input fields. what is the best way to do this in jquery. I tried .text (), it does not work.

`

<html>
  <head>
    <title></title>
    <script type="text/javascript" src="js/jquery.js"></script>

    <script type="text/javascript">


$(document).ready(function(){

   var t = $(":input").text();

   alert(t);
});



    </script>


    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
      <form name="f">
        <input type="text" name="t" value="cake">tes</input>

      </form>
  </body>
</html>

`

Thnks coool

+3
source share
1 answer

You want to $(':input').val().

Using inputas a closing tag is incorrect HTML and will not do anything useful, FYI.

+7
source

Source: https://habr.com/ru/post/1711603/


All Articles