Easy A
Would you like to react to this message? Create an account in a few clicks or log in to continue.


 
HomeHome  Latest imagesLatest images  SearchSearch  RegisterRegister  Log inLog in  

Share
 

 (AJAX => Div) don't work javascript in the div

View previous topic View next topic Go down 
AuthorMessage
xh1dd3nx
Member
Member
xh1dd3nx

Posts : 2
Join date : 2011-04-17

(AJAX => Div) don't work javascript in the div Empty
PostSubject: (AJAX => Div) don't work javascript in the div   (AJAX => Div) don't work javascript in the div EmptyThu 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 ?????
Back to top Go down
Conquer
Member
Member
Conquer

Posts : 1
Join date : 2011-05-05

(AJAX => Div) don't work javascript in the div Empty
PostSubject: Re: (AJAX => Div) don't work javascript in the div   (AJAX => Div) don't work javascript in the div EmptyThu 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.
Back to top Go down
xh1dd3nx
Member
Member
xh1dd3nx

Posts : 2
Join date : 2011-04-17

(AJAX => Div) don't work javascript in the div Empty
PostSubject: Re: (AJAX => Div) don't work javascript in the div   (AJAX => Div) don't work javascript in the div EmptyThu Jun 23, 2011 8:10 am

ok thanks
Back to top Go down
Sponsored content




(AJAX => Div) don't work javascript in the div Empty
PostSubject: Re: (AJAX => Div) don't work javascript in the div   (AJAX => Div) don't work javascript in the div Empty

Back to top Go down
 

(AJAX => Div) don't work javascript in the div

View previous topic View next topic Back to top 
Page 1 of 1

 Similar topics

-
» Javascript HashChange
» Secure Login with javascript
» MUST READ- How to post a JavaScript question!
» javascript values back to python?
» Ajax problem

Permissions in this forum:You cannot reply to topics in this forum
Easy A :: (AJAX => Div) don't work javascript in the div Edit-trash Useless :: Trash-