Create $() Jquery into pure Javascript

I’m trying to create this Jquery code into pure javascript

let container = $('body');

let cursor = $('<div/>').addClass('cursor').html('<svg/></svg>').appendTo(container);

But I got confused when creating a pure javascript selector for this type of selection method from jquery

$('<div/>')

When i try to console $('<div/>') then the output

w.fn.init [div]
 0: div
  length: 1
 [[Prototype]]: Object(0)

Could someone help me to create this jquery code into pure js code

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

// Cache the container
const container = document.querySelector('body');

// Create a new element
const cursor = document.createElement('div');

// Add the className, and innerHTML
cursor.className = 'cursor';
cursor.innerHTML = '<svg></svg>';

// Append it to the container
container.appendChild(cursor);
.cursor { border: 1px solid black; height: 100px; width: 100px; }

Additional documentation


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x