Note that there are some explanatory texts on larger screens.

plurals
  1. POThe Best Way To Represent key/value Pairs In HTML Class Names
    primarykey
    data
    text
    <p>I am binding things to HTML objects using javascript and need a slightly more sophisticated mechanism than just class names.</p> <p>My first approach was to use class names like structure declarations where the binding is on name position as so:</p> <pre><code>Definition = identifier: foo bar baz </code></pre> <p>Encoding some class name with this definition gives</p> <pre><code>&lt;p id="someid" class="identifier bish bash bosh"&gt; &lt;div id="anotherid" class="identifier heebie jeebie"&gt; </code></pre> <p>This can then be read as:</p> <pre><code>{foo: bish, bar: bash, baz: bosh}; {foo: heebie, bar: jeebie} </code></pre> <p>Note that the bindings have different numbers of parameters.</p> <p>This is very fragile. I can't decorate any html elements with additional names (for instance to add jquery behaviours like drag and drop, etc, etc) and is generally a bit shoddy...</p> <p>What I would like to do is represent them as key value pairs like so:</p> <pre><code>&lt;p id="someid" class="id{foo:bish} id{bar:bash} id{baz:bosh} random class"&gt; &lt;div id="anotherid" class="ui-draggable id{bar:jeebie} id{foo:heebie}"&gt; </code></pre> <p>Which allows me to have random positioning and random length of class names on elements provided my id is a sorta GUID (but I can 'make that so' manually easily enough...)</p> <p>Now, <a href="http://www.w3.org/TR/REC-html40/struct/global.html#h-7.5.2" rel="nofollow noreferrer">in theory</a>, classnames are CDATA, so everything should be tickety-boo, but <em>I hae ma doots!</em> particularly on the old cross-browser side...</p> <p>Advice, suggestions, prior art, best practice on the best syntax for KV pairs in class names all gratefully received.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload