2

How to get the current object of the appended element

   var new_htm = "<div class='engagement_data'>" + htm +"</div>";
   $("#addin").append(new_htm);

i want to construct a this for the appended element in jquery how to do this..

Hulk
  • 32,860
  • 62
  • 144
  • 215
  • possible duplicate of [Easier way to get a jQuery object from appended element](http://stackoverflow.com/questions/1443233/easier-way-to-get-a-jquery-object-from-appended-element) – sushain97 Sep 25 '13 at 14:02

2 Answers2

3

Try this...

var $new_htm = $("<div class='engagement_data'>" + htm +"</div>").appendTo("#addin");

.appendTo() returns the object that you append, whereas append() returns the parent object.

raam86
  • 6,785
  • 2
  • 31
  • 46
Reinstate Monica Cellio
  • 25,975
  • 6
  • 51
  • 67
1

Append the element and than:

$this  = $("#addin").find('.engagement_data');

An even better way can bev

$div = $("#addin").append(newHtml).children()

raam86
  • 6,785
  • 2
  • 31
  • 46