Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8181885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:40:13+00:00 2026-06-07T00:40:13+00:00

Is there a Clojurescript library which makes the DOM look like a Clojure data

  • 0

Is there a Clojurescript library which makes the DOM look like a Clojure data structure ? I found a few libraries like Enfocus which do certain kinds of DOM manipulation, but what I want is to be able to treat the DOM like this:

(get dom id) - returns element called id in dom
(get dom id create-fn) - return element if exists, otherwise creates it
(update-in dom [:body this that] update-fn) - set attribute on a DOM element 
(assoc parent-element id child-element) - associate child element with parent
(conj parent child) - append child element to parent element

and so on

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T00:40:16+00:00Added an answer on June 7, 2026 at 12:40 am

    Clojure data structures are all persistent, but in your example it seems like you want to side effect (i.e., hit the DOM in place to change it).

    That’s a pretty procedural/imperative approach, so it may be worth stepping back and reformulating the problem in a more functional style.
    My personal philosophy is to treat “views as data”, and model it using Clojure’s persistent data structures up until the last minute when I need to render.

    Are you familiar with Hiccup?
    The idea is to represent an HTML or SVG DOM using plain vectors and maps:

    [:div {:with "attribute"} "and" [:span "children"]]
    

    which you can construct by composing plain old Clojure functions.
    In Clojure you can render this into HTML (using the original Hiccup library), but there are at least two ClojureScript libraries that render directly into (potentially existing) DOM structures.
    Crate is a close port of Hiccup, and Singult has some additional semantics like D3.js-inspired data binding (Singult is actually written in CoffeeScript, so it’s usable from plain JavaScript and is faster than Crate).

    My C2 library builds data-binding semantics on top of Singult for keeping the DOM in sync with underlying data.
    Consider this template for a TODO list:

    (bind! "#main"
            [:section#main {:style {:display (when (zero? (core/todo-count)) "none")}}
            [:input#toggle-all {:type "checkbox"
                                :properties {:checked (every? :completed? @core/!todos)}}]
            [:label {:for "toggle-all"} "Mark all as complete"]
            [:ul#todo-list (unify (case @core/!filter
                                    :active    (remove :completed? @core/!todos)
                                    :completed (filter :completed? @core/!todos)
                                    ;;default to showing all events
                                    @core/!todos)
                                  todo*)]])
    

    (taken from C2 TodoMVC implementation).
    Things like whether or not the “check all” box is checked is derived directly from the underlying data (stored in an atom).
    Whenever that data changes, the template will be re-run and the dom automatically updated.

    The basic idea is to build mappings in the forward direction from your application data to Hiccup data structures, and then let the library take care of syncing the DOM (adding/removing children, attributes, &c.).
    If you don’t have to concern yourself with the state of the DOM (has this already been added? do I need to toggle some class?) then a lot of incidental complexity falls away.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There are several shading languages available today like GLSL, HLSL, CG, which one to
There are a few ways to get class-like behavior in javascript, the most common
Is there any way to create breakpoints in clojurescript? Either in the repl or
There's a Rails 3.2.3 web application which doesn't use any database. But in spite
There is a directed graph having a single designated node called root from which
There are two intents on the receiver side which are called from the same
There's a bug in FireBug: I accidentally clicked where the line numbers are, which
There's a few previous questions on StackOverflow questioning how one goes about accessing local
There is a div (form) which opens on the click of a button. There
There are a lot of Jquery plugins and libraries. and sometimes I want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.