V
V
Vladislav2021-07-20 08:38:31
JavaScript
Vladislav, 2021-07-20 08:38:31

Why can't I change the height inline style using JS in Yandex maps?

Why can't I change the height inline style using JS in Yandex maps?

let ymaps = document.querySelector('#ymaps111111111111')

ymaps.style.height = '200px'

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Aricus, 2021-07-20
@Aricus

Most likely, you are trying to perform this operation before this element even appears in the DOM. If Yandex maps are added via html, just wrap

window.onload = function() {
   // Ваш скрипт
};

In general, they usually wrap all js code with this, except for classes and functions.
If Yandex maps are loaded via js, you need to track their appearance in the DOM:
$(elem).on("DOMNodeInserted", function (event) { /* ваш код */ });

F
freeExec, 2021-07-20
@freeExec

https://yandex.ru/dev/maps/archive/doc/jsapi/2.0/r...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question