[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 318
  • Last Modified:

Jquery on click function problem

Hello experts.
I 'm trying to use the on('click') function but it is not working.
Any help?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
.qq-uploader-main:hover{background: #CC0000; cursor:pointer;border: 1px solid #DDD;}
</style>
<script type="text/javascript" src="jquery-1.7.1.min.js"></script>
<script type="text/javascript" language="javascript">
$("body").on("click", ".qq-uploader-main", function (e) {
        e.preventDefault();
	alert('test');
});
</script>
</head>

<body>
<div style="width:100%" class="qq-uploader-main"><span>Edit</span></div>
</body>
</html>

Open in new window

0
Panos
Asked:
Panos
  • 2
1 Solution
 
APoPhySptCommented:
try this:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
.qq-uploader-main:hover{background: #CC0000; cursor:pointer;border: 1px solid #DDD;}
</style>
<script type="text/javascript" src="jquery-1.7.1.min.js"></script>
<script type="text/javascript" language="javascript">

$("#Uploader").click(function(e) {
      e.preventDefault();
	alert('test');
});

</script>
</head>

<body>
<div style="width:100%" id="Uploader" class="qq-uploader-main"><span>Edit</span></div>
</body>
</html>

Open in new window

0
 
Tomarse111Commented:
You need to wrap your click function in an on ready or on load function.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
.qq-uploader-main:hover{background: #CC0000; cursor:pointer;border: 1px solid #DDD;}
</style>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript" language="javascript">
	
	$(function(){	
		$("body").on("click", ".qq-uploader-main", function (e) {
		        e.preventDefault();
			alert('test');
		});
	})


</script>
</head>

<body>
<div style="width:100%" class="qq-uploader-main"><span>Edit</span></div>
</body>
</html>
                                  

Open in new window

0
 
PanosAuthor Commented:
Hi.
Tomarse111 you solved the problem. Thank you both.
0
 
PanosAuthor Commented:
thank you .
regards panos
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now