I just wondered if anyone knows of a way to use the .after and .load functions in jQuery at the same time!
What I am trying to achieve, is that when a button within a specific <tr> is a click the .load function is called and the results of the .load are placed are the after <tr> where the button resides!
This is racking my head!
I have tried this:
//Quick Edit
$(".qEdit").click(
function(){
var $pageID = $(this).parents('tr').attr('id');
var $editID = $pageID.replace(/pageID/, "editID");
//Remove Any Other Quick Edits
if ($("tr.quickEdit")) {
$("tr.quickEdit").remove();
}
//Hide Page TR & Display Quick Edit
$(this).parents('tr').hide();
$(this).parents('tr').after(.load('assets/ajax/quickEdit.php', { editID: $editID }));
return false;
}
);
Shouldn’t it be $.load() instead of just .load() ?
BTW. If ($(“tr.quickEdit”)) doesn’t work, since jQuery does not return false when nothing is found, but returns a jQuery object, which evaluates to true.
What I always do instead is
if ($(“tr.quickEdit”).size() > 0)
However, you can simply put
$(“tr.quickEdit”).remove();
whithout any if statement. jQuery doesn’t raise an error if no tr.quickEdit exists.
Although I like your idea of using AJAX for quick edit fields, I wonder if you have also considered the following.
Create a div with an id like “editDiv”
This div has the contents of assets/ajax/quickEdit.php
Whenever someone clicks an .qEdit element, you move “editDiv” so it goes below the tr for which the .qEdit element was clicked. You can than also have a hidden field within this div with the name editID which you can populate with the id of the .qEdit element was clicked.
For example
$('.qEdit').click( function() {
var id = $(this).attr('id');
var $editID = id.substring(id, lastIndexOf('_') + 1);
$('#editID).val($editID);
});
Assuming the hidden field has the editID and every .qEdit element has an id in the form “edit_{editID}”.
It would save bandwith and make thing looks more smooth since there is no AJAX loading time.