• Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses and challenges
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

72
Views
Create $(<div/>) 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

9 months ago · Juan Pablo Isaza
1 answers
Answer question

0

// 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

  • querySelector

  • createElement

  • className

  • innerHTML

  • appendChild

9 months ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post job Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2023 PeakU Inc. All Rights Reserved.