Found 8895 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

288 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

0 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

291 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

11K+ 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

3K+ 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

444 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 can I know which radio button is selected via jQuery?

Arnab Chakraborty
Updated on 23-Jun-2020 09:48:08

291 Views

The jQuery: checked selector can be used in conjugation with the val() to find the value of certain radio button as,$('input[name=radioName]:checked').val()In your query this can be implemented as −Example Live Demo               $(document).ready(function() {          $("input[type='button']").click(function() {             var radioValue = $("input[name='q1']:checked").val();             if(radioValue) {                alert("You select - " + radioValue);             }          });       });            Select a number:       1       2       3    

How to validate a form using jQuery?

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

31K+ 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

11K+ 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

771 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                  

Advertisements