Giter Site home page Giter Site logo

log element's text? about learn-halogen HOT 2 CLOSED

swuecho avatar swuecho commented on July 22, 2024
log element's text?

from learn-halogen.

Comments (2)

JordanMartinez avatar JordanMartinez commented on July 22, 2024

Thanks for this great tutorial. Enjoy reading it!

Glad it's helping you.

delete the line of H.getHTMLELEMENTRef [and I] still get the same behaviour. maybe log the element's text to show the element is the 'my-button' element?

The fact that the same behavior occurs despite deleting that line does not surprise me at all. However, do you understand why it works that way?

I tried to get the text out of the button element, but seems not as easy as I thought.

Looks like there isn't a function innerText :: HTMLElement -> Effect String in purescript-web-html. If there was, you could then write:

handleAction :: HandleSimpleAction State Action
handleAction = case _ of
  PrintExample -> do
    -- Here, we use this reference to do something with the element
    H.getHTMLElementRef (H.RefLabel "my-button") >>= traverse_ \element -> do
      -- in this situation, we'll just state that the element exists
      -- and could be used here
      -- todo: get infor from element
      liftEffect do
        innerTxt <- innerText element
        log innerTxt

One way to get around that limitation is to write the FFI for that function here.

from learn-halogen.

swuecho avatar swuecho commented on July 22, 2024

text <- textContent $ toNode element works. thanks.

from learn-halogen.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.