Renaud is Not Bill Gates
Renaud is Not Bill Gates

Reputation: 2074

Failed to execute 'appendChild' on 'Node'

I'm trying to disable all form elements by a div, so I tried as following:

var form  = elt.find("form:first-child");
// Disable all form elements
form.css('display','relative');
var lightBox = $('div');
lightBox.css({
    'display': 'absolute',
    'top': '0',
    'right': '0',
    'bottom': '0',
    'left': '0'
});
form.append(lightBox);

But I get this error message:

Failed to execute 'appendChild' on 'Node': The new child element contains the parent.

How can I solve this?

Upvotes: 1

Views: 2290

Answers (1)

Michał Perłakowski
Michał Perłakowski

Reputation: 92471

$('div') selects all divs. If you want to create a div, you should use $('<div>') instead.

var form  = elt.find("form:first-child");
// Disable all form elements
form.css('display','relative');
var lightBox = $('<div>');
lightBox.css({
    'display': 'absolute',
    'top': '0',
    'right': '0',
    'bottom': '0',
    'left': '0'
});
form.append(lightBox);

Upvotes: 4

Related Questions