Subject: (AJAX => Div) don't work javascript in the div Thu Jun 23, 2011 8:06 am
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 ?????
Conquer Member
Posts : 1 Join date : 2011-05-05
Subject: Re: (AJAX => Div) don't work javascript in the div Thu Jun 23, 2011 8:07 am
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.
xh1dd3nx Member
Posts : 2 Join date : 2011-04-17
Subject: Re: (AJAX => Div) don't work javascript in the div Thu Jun 23, 2011 8:10 am
ok thanks
Sponsored content
Subject: Re: (AJAX => Div) don't work javascript in the div