Quantcast
Viewing all articles
Browse latest Browse all 1784

Accessing and tweaking Dom elements (maybe related to type conversion?)

  1. I’m abit confuse about type nodeListOf<'a>. What does it mean when you are not giving thing to that type?
  2. How do you know about JsxDOMStyle? (From the javascript thingy I expected the style to be cssStyleDeclaration)
  3. The JsxDOMStyle zIndex is not mutable. I guess I would have to make my own similar Record type with mutable?
  4. I see. I tried reading the doc a bit more and found out about @set_index

Thank you for your advice!! I changed the script to be like this. Is there anything else I should change?

type nodeListOf<'a>
type made_up_style_type_to_test = {mutable zIndex: int}
@scope("document") external querySelectorAll: string => nodeListOf<Dom.element> = "querySelectorAll"
@get external style: Dom.htmlElement => made_up_style_type_to_test = "style"

// do I have to do this ugly conversion always?
external toHTMLElement: Dom.element => Dom.htmlElement = "%identity"
@get_index external get: ('b, string) => 'a = ""
@set_index external set: ('b, string, 'a) => unit = ""

@send external forEach: (nodeListOf<'a>, 'a => unit) => unit = "forEach"

let main: unit => unit = () => {
  let elements = querySelectorAll(".abc")
  elements->forEach(el => {
    el
    ->toHTMLElement
    ->style
    ->get("zIndex")
    ->Console.log
    el
    ->toHTMLElement
    ->style
    ->set("zIndex", 222) //this works with @set_index

    (
      el
      ->toHTMLElement
      ->style
    ).zIndex = 1 //I try to change the property with my homemade css with mutable zindex. this also works!!
  })
}
main()

Viewing all articles
Browse latest Browse all 1784

Trending Articles