Anonymoose
Anonymoose

Reputation: 2461

Jquery selector on HTML

I am trying to use a jquery selector on an HTML line.

var render = "<div id=\"cellContainer\"></div>";
$(render).find("#cellContainer").append("this is a test");
$("#container").html(render);

For some reason it does not output anything. What am I missing ?

Edit: let me clearify that this is a simplification of my actual code so I'm not looking for alternative ways.

JSFiddle

Upvotes: 2

Views: 47

Answers (1)

James Donnelly
James Donnelly

Reputation: 128791

Rather than doing that, you can simply:

$("<div />", {
    id: "cellContainer",
    html: "this is a test"
}).appendTo("#container");

JSFiddle demo.

I suggest you check out both http://learn.jquery.com and http://try.jquery.com.

Upvotes: 5

Related Questions