Explaining Javascript objects inserted in the DOM?

I am working on a personal project using some jQuery / native Javascript programming. I hope someone can clarify the problem that I see with my code. I got confused about the relationship between objects created in Javascript and objects that are part of the DOM.

When using the JQuery UI (tab function), my program behaves differently depending on whether I control my object from the Javascript directory or if I first access it from the DOM API, which makes me think that these two links are not are equal.

Example:

myObject = $(document.createElement("div")).attr("id", "tabs");
$("body").append(myObject);

Now I found that the following example works correctly:

$("#tabs").tabs();

But the following:

$(myObject).tabs();

, , $( "# tabs" ), , , Javascript (myObject)?

- , , DOM? , DOM, id?

+3
1

JS- , jQuery, , , $(...), jquery.

:

myObject = $(document.createElement("div")).attr("id", "tabs");

jquery, :

myObject.tabs();

:

$(myObject).tags();

:

$($(document.createElement(...)...);

, .

, ( ):

var myObject = $("<div></div>").attr("id", "tabs");

var ( , 95% ), jquery JS.

+5

Source: https://habr.com/ru/post/1726625/


All Articles