Santhosh Yedidi Santhosh Yedidi - 1 year ago 113
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.

Answer Source

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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download