Merge pull request #391 from grav/patch-1

Docs: Add special notation for id and classes
This commit is contained in:
Matthew Jaoudi 2018-09-17 11:09:38 -07:00 committed by GitHub
commit 46180032b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 40 additions and 0 deletions

View File

@ -52,6 +52,46 @@ As of reagent 0.8.0, the `class` attribute accepts a collection of classes and w
[:div {:class ["a-class" (when active? "active") "b-class"]}] [:div {:class ["a-class" (when active? "active") "b-class"]}]
``` ```
## Special notation for id and class
The id of an element can be indicated with a hash (`#`) after the name of the element.
This:
```clojure
[:div#my-id]
```
is the same as this:
```clojure
[:div {:id "my-id"}]
```
One or more classes can indicated for an element with a `.` and the class-name like this:
```clojure
[:div.my-class.my-other-class.etc]
```
which is the same as:
```clojure
[:div {:class ["my-class" "my-other-class" "etc"]}]
```
Special notations for id and classes can be used together. The id must be listed first:
```clojure
[:div#my-id.my-class.my-other-class]
```
which is the same as:
```clojure
[:div {:id "my-id" :class ["my-class" "my-other-class"]}]
```
## Special notation for nested elements ## Special notation for nested elements
Reagent extends standard Hiccup in one way: it is possible to "squeeze" elements together by using a `>` character. Reagent extends standard Hiccup in one way: it is possible to "squeeze" elements together by using a `>` character.