I am new to JS and jQuery. I read "JavaScript for children." Went to the machines. We have the code inside the function.

var carHtml = '<img src="car.png">'; var carElement = $(carHtml); carElement.css({position: "absolute", left: car.x, top: car.y}); $("body").append(carElement); 

I do not understand the second line. What have we achieved it?

  • one
    created a jQuery wrapper object around a DOM element (not yet inserted into the page) corresponding to the html from the first line - Igor

1 answer 1

In this case, $ is an alias for the jQuery function.

In the specified line, this function is passed a string that looks like html. In this case, jQuery creates DOM elements, and returns a new jQuery object that references the created elements.