H. Pauwelyn
H. Pauwelyn

Reputation: 14280

append new div and store that div into a variable

I will make a new row on my draw-area what's a section. I append it to the draw-area but I will receive the new tree-row in the variable row. How can I do this? In other words I'll append a new div and store that in a variable. Now I store .draw-area in the variable.

var row = $(".draw-area").append('<div class="tree-row"></div>');

Upvotes: 0

Views: 50

Answers (3)

Manuel Garcia
Manuel Garcia

Reputation: 144

Let's see if I've understood well, you mean this?

$(".draw-area").append('<div class="tree-row"></div>');

And after insert, store it on a variable:

var row = $(".draw-area").last();

Upvotes: 0

H. Pauwelyn
H. Pauwelyn

Reputation: 14280

I've found it:

var row = $(".draw-area").append('<div class="tree-row"></div>').find('div');

Upvotes: 0

cesare
cesare

Reputation: 2118

I think you can do like this:

var row = $("<div class='tree-row'></div>");
$(".draw-area").append(row);

Upvotes: 2

Related Questions