Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The easiest way to get <code>data-*</code> attributes is with <code>element.getAttribute()</code>:</p> <pre><code>onclick="fun(this.getAttribute('data-uid'), this.getAttribute('data-name'), this.getAttribute('data-value'));" </code></pre> <p><strong>DEMO:</strong> <a href="http://jsfiddle.net/pm6cH/">http://jsfiddle.net/pm6cH/</a></p> <hr> <p>Although I would suggest just passing <code>this</code> to <code>fun()</code>, and getting the 3 attributes <strong>inside</strong> the <code>fun</code> function:</p> <pre><code>onclick="fun(this);" </code></pre> <p>And then:</p> <pre><code>function fun(obj) { var one = obj.getAttribute('data-uid'), two = obj.getAttribute('data-name'), three = obj.getAttribute('data-value'); } </code></pre> <p><strong>DEMO:</strong> <a href="http://jsfiddle.net/pm6cH/1/">http://jsfiddle.net/pm6cH/1/</a></p> <hr> <p>The new way to access them by property is with <code>dataset</code>, but that isn't supported by all browsers. You'd get them like the following:</p> <pre><code>this.dataset.uid // and this.dataset.name // and this.dataset.value </code></pre> <p><strong>DEMO:</strong> <a href="http://jsfiddle.net/pm6cH/2/">http://jsfiddle.net/pm6cH/2/</a></p> <hr> <p><strong>Also note that in your HTML, there shouldn't be a comma here:</strong></p> <pre><code>data-name="bbb", </code></pre> <hr> <p><strong>References:</strong></p> <ul> <li><code>element.getAttribute()</code>: <a href="https://developer.mozilla.org/en-US/docs/DOM/element.getAttribute">https://developer.mozilla.org/en-US/docs/DOM/element.getAttribute</a></li> <li><code>.dataset</code>: <a href="https://developer.mozilla.org/en-US/docs/DOM/element.dataset">https://developer.mozilla.org/en-US/docs/DOM/element.dataset</a></li> <li><code>.dataset</code> browser compatibility: <a href="http://caniuse.com/dataset">http://caniuse.com/dataset</a></li> </ul>
    singulars
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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