...

View Full Version : insertAfter, insert Before



Phil Jackson
12-08-2009, 08:11 AM
Hi all i have yet another problem:



function contextMenuWork(action, el, pos) {
switch (action) {
case "delete":
{
$(el).remove();
break;
}
case "insert":
{
$("#copiedElement").html($(el).outerHTML());
break;
}
case "pasteAfter":
{
var copiedElement = $("#copiedElement").html();
copiedElement.insertAfter($(el));
break;
}
case "edit":
{
var copiedElement = $("#copiedElement").html();
copiedElement.insertBefore($(el));
break;
}
}
}

Firebug says copiedElement.insertBefore is not a function but i cant understand why. any help much appreciated.

abduraooft
12-08-2009, 08:21 AM
var copiedElement = $("#copiedElement").html();
copiedElement.insertBefore($(el)); I think the problem lies there. Your variable copiedElement is not a reference to an object. Is it?

Phil Jackson
12-08-2009, 08:42 AM
i've gotten this far..



function contextMenuWork(action, el, pos) {
switch (action) {
case "delete":
{
$(el).remove();
break;
}
case "insert":
{
var copy = $(el).outerHTML();
$("#copiedElement").html(copy);
var child = $("#copiedElement").children()[0];
$(child).attr("id", "tester");
break;
}
case "pasteAfter":
{
$("#copiedElement").children()[0].insertAfter($(el));
break;
}
case "edit":
{
$("#copiedElement").children()[0].insertBefore($(el));
break;
}
}
}


but now getting error:

uncaught exception: [Exception... "Not enough arguments" nsresult: "0x80570001 (NS_ERROR_XPC_NOT_ENOUGH_ARGS)" location: "JS frame :: https://web111.secure-secure.co.uk/snowyswebsolutions.co.uk/scripts/php/previewPage.php#insert :: contextMenuWork :: line 64" data: no]

Line 0

Phil Jackson
12-08-2009, 08:42 AM
line 64 being $("#copiedElement").children()[0].insertBefore($(el));

Phil Jackson
12-08-2009, 09:31 AM
I have managed to get it to work...
But i was wondering if you could yet again help me. This is the code:


$(document).ready(function() {
$("p, ul, li").contextMenu({
menu: 'myMenu'
},
function(action, el, pos) {
contextMenuWork(action, el, pos);
});
$(".openmenu").contextMenu({
menu: 'myMenu', leftButton: true
},
function(action, el, pos) {
contextMenuWork(action, el.parent("tr"), pos);
}
);
});

function contextMenuWork(action, el, pos) {
switch (action) {
case "delete":
{
$(el).remove();
break;
}
case "insert":
{
var copy = $(el).outerHTML();
$("#copiedElement").html(copy);
var child = $("#copiedElement").children()[0];
$(child).attr("id", "tester");
$("#copiedElement").attr("rel", $(child).attr("id"));
break;
}
case "pasteAfter":
{
var copyID = $("#copiedElement").attr("rel");
$("#"+copyID).insertAfter($(el));
break;
}
case "edit":
{
var copyID = $("#copiedElement").attr("rel");
$("#"+copyID).insertBefore($(el));
break;
}
}
}

what it does is cuts and pastes selected content. But once to content is pasted, you cant copy that element ( i think due to because its not in the "DOM" (sorry i dont know the technical jargon) ) previously stated here:


$("p, ul, li").contextMenu({
menu: 'myMenu'
},

How do i add the pasted elements into the "DOM". Please correct my terminology if im using it in the wrong context. Many thanks.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum