Help! Using document + HTMLComponent

I am trying to embed a calendar dynamically via a Wix Code Dynamic Page. I have added a Wix ‘HTML Code’ element to my page and set the ‘Code’ setting to the following:

  1. I need to be able to change the ‘data-id’ attribute on the top div element within the $w.onReady() event. I cannot seem to figure this out.

  2. Also, whenever I try to write the following line of code in this event:

document.getElementById(“calDiv”)

i get the following error: “document is undefined”

are we not allowed or able to use the DOM in this traditional way?

  1. if necessary, can I replace the entire code fragment for the ‘HTML Code’ element? I do not see a property for that in the code editor?

Thanks for all the help in advance!

Hi,

WixCode allows all Javascript, except access to the DOM. Wixcode handles DOM access itself via the $w API.

Yisrael

But it seems that you can only get at DOM elements that are created by Wix. so how do you manipulate an element in a custom HTML block? Thanks!

Aha - now I think I understand what you’re trying to do. Sorry, I jumped a bit too quickly before.

I tried your code in an $w.HtmlElement and it worked just fine - but you know that. However, the code in the HtmlElement is sandboxed so it can’t talk back and forth to the page. In order to get around this restriction, you will need to send messages.

You can find out all you need to know in the article Working with the HTML Component in Wix Code . I’ve done this myself and it works pretty nicely.

Have fun,

Yisrael

Why cant I set the height if we have access to their dom elements? How does posting a message talk to a custom element you have in the HTML Code?

@info59086 What are you trying to do?

@yisrael-wix trying to resize my iframe dynamically. Cant believe this isnt available.

@info59086 It can’t be done.

@info59086 Cant believe it either…

Is there still no way to resize an iFrame at all? What about with Custom Elements?

@fernando-rocha Yes! you can.
Check this article i just create for you