Santhosh Yedidi Santhosh Yedidi - 4 months ago 6
jQuery Question

In Jquery how to refer javascript's element created by document.createElement

I have a code already written in javascript:

var objTo = document.getElementById('krishna')
var href1 = document.createElement("div");
href1.setAttribute("style","float: left");

Already so many elements are appended to href1 in javascript.

I want to add some more elements to href1 using jquery

I tried

it says
href1.append is not a function

How to use jquery append to append an element to href1.


You need to turn the native element into a jQuery object. Native elements don't recognize jQuery methods



If you want to do all this with jQuery alone the code is quite simple

// create new <div> element and apply style
var href1 = $("<div>").css('float','left');
// append to id=krishna