JavaScript JavaScript variable equals jQuery selector creates open and closing tags. Why? javascript variable equals function,javascript variable equals or,javascript variable

Please be nice. My first question here. I'm learning JavaScript and jQuery. Google isn't much help because I don't know how to ask the right question. Need human intervention please. I'm trying to figure out what is going on with this simple bit of code:

var myVar = $("<p>");

This creates an opening and closing <p> tag and I don't understand why.

Next, I'll add this paragraph to an existing element #myDiv. For example:

$("myDiv").html(myVar); results in the following:

<div id="myDiv"><p></p></div>

Continuing...

$("myDiv").html(myVar.text("A string for the paragraph"));

Results in:

<div id="myDiv"><p>A string for the paragraph</p></div>

Why does that first snippet create an opening and closing <p> tag? What is this called?

Answer:1

It's simply a more concise method of this in pure JavaScript:

var myVar = document.createElement("p");

And that goes to jQuery like this:

var myVar = $("<p></p>");

And because it's jQuery, and it gets more and more concise, it eventually becomes:

var myVar = $("<p>");
Answer:2

new Array // outputs [] [] // outputs [] But new Array === [] is false. Why so? console.log(new Array === [])

new Array // outputs [] [] // outputs [] But new Array === [] is false. Why so? console.log(new Array === [])

I've written a function to turn a string such as 'aaazeeeee' into a new string of 'aaa z eeeee' this is the code I've tried that works const groupCharacters = signature => { let ...

I've written a function to turn a string such as 'aaazeeeee' into a new string of 'aaa z eeeee' this is the code I've tried that works const groupCharacters = signature => { let ...

  1. refactoring with function

Is it possibile to use an inline return with javascript map function? Instead of doing array.map(token => { var x=new Object(); x[token]=words[token]; return x;} ) I would like to do it inline as ...

Is it possibile to use an inline return with javascript map function? Instead of doing array.map(token => { var x=new Object(); x[token]=words[token]; return x;} ) I would like to do it inline as ...

  1. javascript inline function onclick
  2. javascript inline function call
  3. javascript inline function example
  4. javascript inline function with parameters
  5. javascript inline function scope
  6. javascript inline function syntax
  7. javascript inline function u003d
  8. javascript inline function html
  9. javascript inline function return value
  10. javascript inline function return object
  11. javascript inline function expression
  12. javascript inline function performance
  13. javascript inline function definition
  14. javascript inline function pass parameter
  15. javascript inline function variable scope
  16. javascript inline function callback
  17. javascript inline function call onclick
  18. javascript inline function return
  19. javascript inline function arrow
  20. javascript inline function event

I have the following code: const array = [{ a: 'a', b: 'b' }]; console.log(...array); const store = { obj: ...array } console.log will print the results just fine. However, ...

I have the following code: const array = [{ a: 'a', b: 'b' }]; console.log(...array); const store = { obj: ...array } console.log will print the results just fine. However, ...

  1. canvas
  2. canada
  3. cancelled
  4. canceled vs cancelled
  5. cancun
  6. canada goose
  7. cane corso
  8. canes
  9. canadian prime minister
  10. cancun flights
  11. canker sore
  12. candy
  13. cancer
  14. canon
  15. canvas prints
  16. cancer sign
  17. candace owens
  18. canada news
  19. candytopia
  20. canlis