JQuery-added HTML elements do not pick up CSS styles with crate & clj-js

Start a rather interesting task.

An element created as html and inserted into the page via jquery does not capture the assigned styles.

The style is in HTML, but the browser (Chrome, Firefox) doesn't render it at all.

The generated html can be saved through the browser and the HTML file when opened by DOES is styled.

The same code generated via javascript directly (bypassing the box) or using an explicit html string from within the clojurescript also has the correct styling.

It seems that the problem is only related to the items generated by the boxes.

eg:

(-> (jquery "body")         
  (.append (crate/html [:h1{:class "red"} "Test inside a jquery"]) ))))

      

If the red class simply defines:

.red {
color:red;
}

      

I've tried several box options here, including defpartial, defhtml with the same results. Same results using jayq or no jquery wrapper. Likewise, using various jquery methods (inner, append, html, etc.).

Am I missing something very obvious?

+3


source to share


3 answers


It turns out the main problem was that I had a function in my application called "get"

(defn get [])

      



This may have conflicted with clojure.core / get.

Removing or renaming this function resolves the problem and the CSS is applied correctly. Very strange.

0


source


Can you try:



(-> (jquery "body")         
  (.append (crate/html [:h1.red "Test inside a jquery"]) ))))

      

+3


source


Since your function call is only for side effects, you must make sure that lazy evaluation is not a problem:

(doto (jquery "body")
  (.append (crate/html [:h1{:class "red"} "Test inside a jquery"])))

      

+1


source







All Articles