objecthub-io / ObjectHub

ObjectHub is an open repository for software objects and a development platform.
2 stars 1 forks source link

document.querySelector does not work as expected #262

Closed DenisNedvigok closed 7 years ago

DenisNedvigok commented 7 years ago

When you use document.querySelector with one item on the HTML markup in MicroApp (f.e. document.querySelector(‘button’)) chances are that you get some object that is not within your HTML markup.

Please refer example below: HTML markup:

<html>
<body>
 <button type="button" class="btn btn-primary">Convert</button>
</body>
</html>

JavaScript:

app.init = function(cb) {
    console.log(document.querySelector('button'));
    cb();    
};

Console will show the button not from the HTML markup in HTML tab, but some other button from the DOM.

objecthub-io commented 7 years ago

Yes, the way that JS works requires to select elements in Micro Apps in a special way, by using the $("button", elem) selector.

More infos on the following page under the JavaScript section: https://objecthub.io/docs#/Micro_App

We can't really think of another way to restrict JS from only accessing a part of the DOM. Is there another option?

objecthub-io commented 7 years ago

Closing this issue now!