Button Click in jQuery

Im new for jQuery. I want to use a button click event to raise a warning window. This is my code, but it does not seem to work. Help! you are welcome

<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Jquery Basic</title> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> <script> $(document).ready(function() { $('submit1').click(function() { alert("JQuery Running!"); )}; }); </script> </head> <body> <a>JQuery Test Page</a><br> <input id="submit1" type="button" value="Submit"/> </body> </html> 
+6
source share
5 answers

You are missing # from the id selector. Try the following:

 $(document).ready(function(){ $('#submit1').click(function(){ alert("JQuery Running!"); }); }); 
+20
source

The answer has already been sent by @Rory, but you can also try this

 $(document).ready(function(){ $('#submit1').on('click',function(){ alert("JQuery Running!"); }); }); 
+3
source

You are missing # in front of your id . You need to use # if you want to select based on id and . if you want to select based on css-class .

Try $('#submit1').click(function(){ .

+1
source

if you want to get the input value "text field" and put the value in paragraph "para1", it decides if you are in doubt. I helped.:)

 $(document).ready(function(){ $("#submit1").click(function() { alert($("#textbox").val()); $("#para1").text($("#textbox").val()); }); }); 
+1
source
 $(function(){ $("#submit1").live('click',function() { alert("hi!"); }); }); 
+1
source

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


All Articles