My HTML code has about 100 divs and hyperlinks which are almost identical:
<div><a href="#" onclick="load_edit(1, 1);" class="painike">Edit 1</a></div>
<div><a href="#" onclick="load_edit(1, 2);" class="painike">Edit 2</a></div>
My jQuery code should load load_edit.php from the server and replace the hyperlink which called the function. Anyway, my code does not replace a hyperlink with HTML code, and I do not know the reason. What is wrong?
function load_edit(kaavio, ottelu) {
$.post( "load_edit.php", { kaavio: kaavio, ottelu: ottelu } )
.done(function( data ) {
alert( "Data Loaded: " + data );
$(this).replaceWith(data); // this does not work
});
}
On the other hand, because I have about 100 hyperlinks which are calling the same function, it would be nice to hear, how this could be done better. I would like to get rid of my inline JavaScript code and improve the function.