All TalkersCode Topics

Follow TalkersCode On Social Media

devloprr.com - A Social Media Network for developers Join Now ➔

jQuery On Keyup

Last Updated : Mar 11, 2024

jQuery On Keyup

In this article we will show you the solution of jQuery on keyup, here we are going to show you example to achieving result with the help of Keyup() and css() method.

The keyup() method is an inbuilt method in jQuery which is used to triggers keyup event whenever user releases the key in keyboard.

Then css() method used for notify user when reach keyup event activated state.

Step By Step Guide On jQuery On Keyup :-

Here we defined html block with input element, which contains id and class attributes with respective values then empty p tag for display noyify message.

In script block we defined ready method, which is loads source code on browser.

Within that keyup() method append with input element to insert keyup event then user can identify its activation state by css() and text() method uses.

<!DOCTYPE html>
<html>
<head>
  <title>keyup event in jquery</title>
</head>
  <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
  <script>
    $(document).ready(function(){
      $("#inpVal").keyup(function(){
        $(".inp").css("background-color","yellow");
        $("p").text("Keyup Event Is Activated....");
      })
    })
  </script>
<body>
  <input type="text" class="inp" id="inpVal" />
  <p></p>
</body>
</html>
  1. <!DOCTYPE html> tag which is instruct the web browser about what version of HTML file written in and it’s not have any ending tag.
  2. The<html> tag is used to indicate the beginning of HTML document.
  3. As above shown <head> tag is contain information about webpage and external file links are declared here. <title> tag is used for set the webpage title.
  4. Here we imported open source jquery library support file which is needed for coding using jquery in program.
  5. Both <head> and <title> tags having their pair end tag, so we need to close the ending tags respectively. If you’re not closed anyone of ending tag properly that is also affect the webpage result.
  6. <body> tag is beginning of main coding part because it contain coding of entire website blocks and elements described here.
  7. In script we defined ready function, there specified keyup method with input element by specifying id 'inpVal'.
  8. Then within that function defined css() method with input tag by specifying its class attribute value. And the css() method changing background color when finds keyup event trigger by user.
  9. After that we binds notification message with p tag with the help of text() method.
  10. In body block we defined input element with id 'inpVal' and class 'inp' attribute values. The empty paragraph tags help you to display defined alert message on webpage.
  11. Both </body>,</html> tags closed respectively. </body> tag indicates the end of body, Then </html> tag indicates the end of HTML document.

Conclusion :-

In conclusion now we are able to know how to use keyup event on input element using jquery.

Before execution of program we needs to confirm internet connection because then only that jquery file will supports defined jquery codes in document without any error.

When we executes this program on browser we can see input text box. Now user need to type something on text box then you can see background color changed to yellow color and below appeared alert message.

I hope this article on jQuery on keyup helps you and the steps and method mentioned above are easy to follow and implement.

Author Image About Amruta

Amruta is an Experienced web developer with 4 years for experience she completed her master's with MCA and passionate about programming Languages for creating technical contents like HTML, CSS, JavaScript, Java, Python, PHP, jQuery.

Follow Amruta On Linkedin 🡪