Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Click event on DOM element inserted with AJAX

AJAX ajax element

  • Please log in to reply
1 reply to this topic

#1 Bertan

Bertan

    CC Regular

  • Member
  • PipPipPip
  • 42 posts

Posted 22 December 2011 - 09:08 AM

I tried to put the click event inside ajax.php and then it works, but if in test.php it doesn't work is it any way to get this to work from test.php?

Thanks for any help,
Bertan

test.php
<!DOCTYPE html>
<html>
	<head>
		<title>Image</title>
		<meta charset="UTF-8" />
		<script src="http://code.jquery.com/jquery.min.js"></script>
		<style>
		#content {
			padding: 20px 0;
			background: #f4f4f4;
			text-align: center;
		}
		ol, ul {
			list-style: none outside none;
		}		
		</style>
	</head>
	<body>

		<div id="content">
			<ul class="imgRow">
			</ul>
		</div>
		<script>
 		$(function() {
		
 			loadContent();
			
			function loadContent() {
				var index = true;
				
				$(function () {
					$.ajax({
						type: "GET",					
						url: "ajax.php",
						dataType: "html", 
						success: function(html) {                     
							$(".imgRow").html(html);							
						} 
					});
				});
				setTimeout(loadContent, 10000);
			}
			
 			$("#text").click(function(data) {
				alert("Hello");
			});	 	
		}); 		
		</script>		
	</body>
</html>

ajax.php
<?php
echo 
	'<li id="text">				
		Aenean ultricies mi vitae est. Mauris placerat eleifend leo.
	</li>';
?>

  • 0

#2 Bertan

Bertan

    CC Regular

  • Member
  • PipPipPip
  • 42 posts

Posted 23 December 2011 - 02:26 AM

Nevermind got it working using live
  • 0





Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download