Filip Filip - 5 months ago 24
HTML Question

JQuery not adding element not giving an error?

I am trying to add a content

to an element and also a
element to another. The content dive gets added into the html, but not the h1 and I'm not getting any error either.

This is the relevant code:

var content = $("<div>").attr({"class": "section-content", "id": "content",
"style": "max-height: 500px;overflow-y: scroll; padding-top:0;padding-
console.log("Adding content");
var textcont = $("<h1>").appendTo(".content");
console.log("Added content");

What do I need to change to get the h1 added?

Answer Source
var textcont = $("<h1>").appendTo(".content"); 

tries to add h1 to a div with a class of name content. however the div you add has a class named section-content and an id named content.


var textcont = $("<h1>").appendTo(".content");


var textcont = $("<h1>").appendTo(".section-content");


var textcont = $("<h1>").appendTo("#content");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download