0

I have the folowing script; The problem is that i can use the jquery scripts inside the loaded file

index.html

<html> 
<head> 
 <title>Ajax with jQuery Example</title> 
 <script type="text/JavaScript" src="jquery.js"></script> 
 <script type="text/JavaScript"> 
 $(document).ready(function(){ 
$.ajax({
  url: 'ajax/test.html',
  success: function(data) {
    $('#wrapper').html(data);
  }
});

  $("A").click(function(){ 
     alert("test inside loaded file");
   }); 

}); 
 </script> 
</head> 
<body> 
 <div id="wrapper"> 
 </div> 
</body> 
</html>

ajax/test.html

<A HREF="document2.html" TABINDEX="4">test alert</A>

The problem he will give no alert when i click on the loaded file

3 Answers 3

2

Try changing the following line:

$("A").click(function(){ 
     alert("test inside loaded file");
   }); 

to

$("A").live('click',function(){ 
     alert("test inside loaded file");
   }); 

By using the Live() method you bind to all <a> tags now and in the future, using .click() only binds to the matching elements that currently exist.

Sign up to request clarification or add additional context in comments.

Comments

1

use

$("A").live("click", function(){ 
     alert("test inside loaded file");
}); 

Comments

1

You'll need to use live() to attach the event to all elements which match the current selector, now and in the future, instead of click().

http://api.jquery.com/live/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.