Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-22-2011, 10:01 AM   PM User | #1
inibir
New to the CF scene

 
Join Date: Jun 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
inibir is an unknown quantity at this point
(AJAX => Div) don't work javascript in the div

hello all

i create one div and include by ajax (html code) but the problen, the jquery his don work into the div

example:

Code:
<script src="http://code.jquery.com/jquery-1.3.js"></script>
<style>
div{
	border:1px solid #000;
	width:10%;
	padding:15px;
	margin: 5px;
}
</style>
<a href='JAVASCRIPT:New_code_div()'>Click Here</a> for change code in div<br>
<div id = 'id_div'>
Original code<br>
<a href='JAVASCRIPT:send_msg()'>msg from JS</a><br>
<a href='#' class='msg'>msg from JQuery</a><br>
</div>
<script>
function New_code_div(){
	x = document.getElementById('id_div');
	x.innerHTML = "include code<br><a href='JAVASCRIPT:send_msg()'>msg from JS</a><br><a href='#' class='msg'>msg from JQuery</a>";
}
function send_msg(){alert('hello from JS')}

$(document).ready(function(){
	$(".msg").click(function(){
		alert("hello from JQuery");
	});
});
</script>
any solution for this problem ?????
inibir is offline   Reply With Quote
Old 06-22-2011, 10:09 AM   PM User | #2
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 531 Times in 525 Posts
devnull69 will become famous soon enough
Yes

The jQuery .click() handler can only bind to elements that already exist. You are adding class "msg" elements later but .click() is not bound to those elements.

That's what .live('click', ...) is for. live will account for "future" elements, too.
devnull69 is offline   Reply With Quote
Old 06-22-2011, 10:15 AM   PM User | #3
inibir
New to the CF scene

 
Join Date: Jun 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
inibir is an unknown quantity at this point
ok thanks
inibir is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:32 AM.


Advertisement
Log in to turn off these ads.