That approach can be made to work but it is generally considered better to attach event handlers in javascript rather than HTML.
<?php
if(isset($_POST['bu'])){
$data = 'text <a href="#">alert</a>';
echo $data;
}
?>
function getdatafromfile(){
var bu = 'bu';
$.ajax({
type: 'POST',
url: 'phpfile.php',
data: {bu: bu},
success: function(msg){
$("#msg").html(msg).find('a').click(function(){
something();
return false;//which ever way you attach it, be sure to return false from the handler to suppress the <a> tag's default hyperlink action.
});
}
});
}
Airshow
Airshow
WiFi Lounge Lizard
2,682 posts since Apr 2009
Reputation Points: 321
Solved Threads: 372
What you are trying to write is generally called a "Create, Read, Update, Delete" (CRUD) interface.
There's no reason why handlers for all the buttons should not be attached in javascript.
Try a web search and you should find some sample scripts.
Airshow
Airshow
WiFi Lounge Lizard
2,682 posts since Apr 2009
Reputation Points: 321
Solved Threads: 372
Personally, I wouldn't attempt this sort of thing without jQuery. Raw javascript would take longer to write and would be far more volumous (though it might actually be more efficient).
jQuery takes some getting used to but is very rewarding once you have made the investment.
The best jQuery programmers are the ones who were good javascript programmers first, so yes carry on with your raw js approach with a view to translating your code to jQuery at some point in the future when time permits.
Airshow
Airshow
WiFi Lounge Lizard
2,682 posts since Apr 2009
Reputation Points: 321
Solved Threads: 372