Found 8591 Articles for Front End Technology

How to know which key was pressed in a form input using jQuery?

Kristi Castro
Updated on 20-Jun-2020 07:48:16

380 Views

To know which key was pressed in a form input using jQuery, use the jQuery keydown event. You can try to run the following code to learn how to detect key pressed in a form input −ExampleLive Demo               $(document).ready(function(){       $('#myinput').keydown(function(e) {         var newkey = 'Key code = ' + e.which + ' ' + (e.ctrlKey ? 'Ctrl' : '') + ' ' + (e.shiftKey ? 'Shift' : '') + ' ' + (e.altKey ? 'Alt' : '');         $('#mykey').text(newkey);         return false;       });     });       Press any key:     The key you press is visible here with keycode.

How to detect Ctrl+Enter in textarea using jQuery?

Kristi Castro
Updated on 30-Jul-2019 22:30:23

58 Views

$(document).ready(function(){ $('#myinput').keydown(function(e) { var newkey = 'Key code = ' + e.which + ' ' + (e.ctrlKey ? 'Ctrl' : '') + ' ' + (e.shiftKey ? 'Shift' : '') + ' ' + (e.altKey ? 'Alt' : ''); $('#mykey').text(newkey); return false; }); });

How to detect pressing Enter on keyboard using jQuery?

Kristi Castro
Updated on 20-Jun-2020 07:46:52

350 Views

To detect pressing Enter on keyboard, use the keup() function with keyCode. You can try to run the following code to learn how to detect pressing Enter on keyboard using jQuery −ExampleLive Demo                          $(document).ready(function(){          $('textarea').bind("enterKey",function(e){          alert("You have pressed Enter key!");       });       $('textarea').keyup(function(e){          if(e.keyCode == 13)          {             $(this).trigger("enterKey");          }       });    });            Press Enter below         Press Enter below 

How to validate email using jQuery?

Kristi Castro
Updated on 20-Jun-2020 07:36:39

12K+ Views

To validate email using jQuery, use the regex pattern. You can try to run the following code to learn how to validate email using jQuery −ExampleLive Demo               $(document).ready(function() {       $('.error').hide();       $('#submit').click(function(){         var name = $('#name').val();         var email = $('#email').val();         if(name== ''){           $('#name').next().show();           return false;         }         if(email== ''){           ... Read More

How to get current URL in jQuery?

Arnab Chakraborty
Updated on 22-Jun-2020 07:56:43

4K+ Views

For getting the current URL you can use attr() method or window.location.Example url               $(document).ready(function () {          $("button").click(function () {             alert($(location).attr('href'));             alert(window.location);          });       });     Display URL

How to get current URL in JavaScript?

Arnab Chakraborty
Updated on 21-Jun-2020 14:20:51

597 Views

The window.location object can be used to get the current URL.window.location.href returns the href(URL) of the current page.I am using these code in my MVC projet.Example                                          var iid=document.getElementById("dd");         alert(window.location.href);       iid.innerHTML = "URL is" + window.location.href;    

How to validate a form using jQuery?

Arnab Chakraborty
Updated on 09-Sep-2023 23:26:40

32K+ Views

At first you have to make a html form like. Validation of a form First name: Last name: Email: Now use jQuery validation plugin to validate forms' data in easier way.first, add jQuery library in your file. then add javascript code: $(document).ready(function() {    $("#form").validate(); }); Then to define rules use simple syntax.jQuery(document).ready(function() {    jQuery("#forms).validate({       rules: {          firstname: 'required',          lastname: 'required',          u_email: {             required: true,   ... Read More

How can I remove all child elements of a DOM node in JavaScript?

Arnab Chakraborty
Updated on 11-Aug-2022 10:45:43

14K+ Views

Suppose you are building a web app that manages the data of daily tasks, the user inserts the task and a list of tasks gets formed. But at some point in time, the user wants to remove all the tasks from the list and wants to make the list empty. So, as a developer, you should know how to remove all the child elements from the DOM node. To remove all the elements from the DOM node we have the following approaches. By iterating the DOM nodes and using the removeChild method. By Erasing the innerHTML value to a ... Read More

How to select ALL children (in any level) from a parent in jQuery?

Kristi Castro
Updated on 20-Jun-2020 07:35:38

1K+ Views

To select all children from a parent in jQuery, use the find() method. You can try to run the following code to select ALL children in any level −ExampleLive Demo        .myclass * {      display: block;      border: 2px solid lightgrey;      color: lightgrey;      padding: 5px;      margin: 15px;    }         $(document).ready(function(){     $('ul').find('*').css({"color": "red", "border": "2px solid green"});   });     div - great-grandparent   ul    li- child - level 1      ul- child - level 2        li- child - level 3        li- child - level 3                  

Why do we use JSON.stringify() method in jQuery?

Kristi Castro
Updated on 20-Jun-2020 07:32:07

551 Views

JSON or JavaScript Object Notation is a lightweight text-based open standard designed for human-readable data interchange. Use the JSON.stringify() method to convert a JavaScript object into a string.You can try to run the following code to learn how to work with JSON.stringify() method −ExampleLive Demo JSON string is created above   var v = { "name":"Amit", "Rank":1, "city":"India"};   var newJSON = JSON.stringify(v);   document.getElementById("test").innerHTML = newJSON;

Advertisements