Filip Filip - 24 days ago 5
HTML Question

JQuery not adding element not giving an error?

I am trying to add a content

<div>
to an element and also a
<h1>
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-
bottom:0;"}).appendTo(".Extrablox");
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.

change

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

to

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

or

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