0

I am trying to load in some HTML trough Ajax. The HTML has a funtion assigned to it with the ONCLICK attribute. Now when i execute the code the function is completely ignored. The HTML is loaded in perfectly.

Below is a simplified version of what i am trying to do.

PHP code for creating the HTML (gethtml.php):

$html = '<a onclick="thefunction()">Click this to trigger JS function</a>';
$data = array(
    'html' => $html
);
echo json_encode($data);

Loading the HTML trough javascript (main.html):

function load_HTML()
    {
        $.ajax({
            url:"actions/gethtml.php",
            method:"POST",
            dataType:"JSON",
            success:function(data)
            {
                $('#container_id').html(data.html);
            }
        })
    }

Javascript function for loaded HTML (main.html):

function thefunction(){
   //any function
}

I hope anyone can help me!

Wibo Kuipers
  • 83
  • 1
  • 2
  • 11

0 Answers0