Found 766 Articles for JQuery

How to check if onClick exists on element in jQuery?

ARPIT ANAND
Updated on 14-Feb-2020 08:01:05

505 Views

These codes might help you −$('body').click(function(){ alert('test' )}) var foo = $.data( $('body').get(0), 'events' ).click // you can query $.data( object, 'events' ) and get an object back, then see what events are attached to it.  $.each( foo, function(i,o) {     alert(i) // guid of the event     alert(o) // the function definition of the event handler });

How to check if event exists on element in jQuery?

Kristi Castro
Updated on 19-Jun-2020 12:47:44

3K+ Views

To check if event exists on element in jQuery, check for the existing events on the element. Here, I have set the div −   This is demo text. Click here! When you click div, then the alert generates which I have set using the div id:$("#demo").click(function() {   alert("Does event exists? - "+hasEvents); });You can try to run the following code to check if event exists −ExampleLive Demo               $(document).ready(function(){       $("#demo").click(function() {         alert("Does event exists? - "+hasEvents);      });      var events = $._data(document.getElementById('demo'), "events");      var hasEvents = (events != null);    });         This is demo text. Click here!

How to enable and disable submit button using jQuery?

Kristi Castro
Updated on 20-Jun-2020 07:15:21

919 Views

To enable and disable submit button, use the jQuery prop() method. You can try to run the following code to enable and disable submit button using jQuery −ExampleLive Demo               $(document).ready(function() {       $('#register').click(function() {         $(this).prop('disabled',true);         $("#content").show();         setTimeout(function(){           $('#register').prop('disabled', false);         },3000);      });    });               The above button disables for 3 seconds, on clicking.                  

Can I submit form with multiple submit buttons using jQuery?

Kristi Castro
Updated on 20-Jun-2020 07:14:15

2K+ Views

Yes, you can submit form with multiple submit buttons. Attack a custom click handler to all the buttons and the check which button is clicked.ExampleLive Demo               $(document).ready(function(){       $("#myform button").click(function (ev) {       ev.preventDefault()       if ($(this).attr("value") == "button1") {                     alert("First Button is pressed - Form will submit")         $("#myform").submit();       }       if ($(this).attr("value") == "button2") {         alert("Second button is pressed - Form did not submit")       }     }); });     First Button   Second Button

How to create div dynamically using jQuery?

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

1K+ Views

To create a div dynamically, use the html() method. You can try to run the following code to learn how to create a div dynamically on button click −ExampleLive Demo               $(document).ready(function(){       $("button").click(function(){         $("body").html("This is a new div.");       });     });   Create a new div This is demo text.

How to set the content of a textarea using jQuery?

Arnab Chakraborty
Updated on 21-Jun-2020 17:10:30

2K+ Views

On clicking the tag,the content is dispaying inside the textarea.Example Live Demo    $(document).ready(function () {       $("a").click(function () {          $("#txt1").val("I AM DISPLAYING IN THE TEXTAREA");       });    });     Quires TEXTAREA ::

How to get the content of a textarea using jQuery?

Arnab Chakraborty
Updated on 21-Jun-2020 17:08:12

533 Views

Here I am using one textarea and one button.The first textarea is used for user input then click the button and display the value in the alert box.Example Live Demo                    $(document).ready(function () {             $("button").click(function () {                var dim = $("#txt").val();                alert(dim);             });          });     Click Here

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 

Advertisements