-1

I have this page:

<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
  <title>test</title>
  <script src="jquery-2.1.1.min.js"></script>
  <script language="javascript" src="ajax.js"></script>
  <script>
    $(document).ready(function() {
      $('#input').keyup(function() {
        $('#output').html($(this).val().replace(/\n/g,'<br/>')); 
      });
    });
  </script>
</head>

<?php
ini_set("display_errors","On"); 
    echo "<div id=\"UpdateArea\">";
        echo "<input type=\"button\" value=\"type here\" onClick=\"ShowPage()\">";
    echo "</div>";
}

?>
</html>

And when I push the button it loads this into the UpdateArea Div:

<?php

echo "<textarea id=\"input\" rows=\"10\" cols=\"50\" class=\"textarea\"></textarea><br><br><br>";

echo "<div id=\"output\"></div>";

?>

But the jQuery wont Work on the Ajax loaded contents :/ So the input won't show up ind the output div.. Why is that?, I'm new to jQuery, so it might be a obvious problem. I would really appreciate some help :)

The Jquery Works fine if I include the script a jQuery on a page for it self and load it.

Kind regards Juel

Shiladitya
  • 12,003
  • 15
  • 25
  • 38
Juel
  • 3
  • 1
  • Can you please redirect me to the duplicate please, I have searched, but no luck :( – Juel Feb 05 '15 at 07:08

1 Answers1

0

You need to use event delegation for attaching events to dynamically added elements:

$(document).on('keyup','#input',function() {
   $('#output').html($(this).val().replace(/\n/g,'<br/>')); 
});
Milind Anantwar
  • 81,290
  • 25
  • 94
  • 125