Foren
How to put the attribute "data-userId"
l ll, geändert vor 9 Jahren.
How to put the attribute "data-userId"
Regular Member Beiträge: 158 Beitrittsdatum: 12.12.11 Neueste Beiträge
Hi!
3 and 4 lines not work
var el = A.Node.create('<div></div>');
el.set('id',userId);
el.set('data-userId',userId);
el.setData('data-userId',userId);
3 and 4 lines not work
Kyle Joseph Stiemann, geändert vor 9 Jahren.
RE: How to put the attribute "data-userId"
Liferay Master Beiträge: 760 Beitrittsdatum: 14.01.13 Neueste Beiträge
Hi,
Try using element.setAttribute() instead of Node.set():
el.setAttribute('data-userId',userId);
- Kyle
Try using element.setAttribute() instead of Node.set():
el.setAttribute('data-userId',userId);
- Kyle
l ll, geändert vor 9 Jahren.
RE: How to put the attribute "data-userId"
Regular Member Beiträge: 158 Beitrittsdatum: 12.12.11 Neueste Beiträge
I can not mix aui and pure js.
A.Node.create('<div data-userid="</code></pre><br /><img alt=" emoticon" src="@theme_images_path@/emoticons/smile.gif"></div>
Evan Thibodeau, geändert vor 9 Jahren.
RE: How to put the attribute "data-userId"
New Member Beiträge: 14 Beitrittsdatum: 29.03.12 Neueste Beiträge
Instead of using ".set" try using ".attr" like this:
el.attr('data-userId', userId);
Kyle Joseph Stiemann, geändert vor 9 Jahren.
RE: How to put the attribute "data-userId"
Liferay Master Beiträge: 760 Beitrittsdatum: 14.01.13 Neueste Beiträgel ll:
I can not mix aui and pure js.A.Node.create('<div data-userid="</code></pre><br /><img alt=" emoticon" src="@theme_images_path@/emoticons/smile.gif"></div>
<br>Why not?<br><br><a href="http://jsfiddle.net/qypt9tcx/1/">This code works perfectly for me by the way:</a><br><br><span style="font-family: Courier New">var el = A.Node.create('<div></div>');<br>el.set('id',userId);<br>el.setAttribute('data-userId',userId);</span><br><br>- Kyle
David H Nebinger, geändert vor 9 Jahren.
RE: How to put the attribute "data-userId"
Liferay Legend Beiträge: 14919 Beitrittsdatum: 02.09.06 Neueste Beiträge
Wait, isn't the setData() and getData() methods supposed to be preferred over direct attribute access? The whole point was to treat the attribs as keyed data and using the data methods enforces this pattern.
So in that case the OP should use el.getData("userId") and el.setData("userId", userId).
So in that case the OP should use el.getData("userId") and el.setData("userId", userId).
l ll, geändert vor 9 Jahren.
RE: How to put the attribute "data-userId"
Regular Member Beiträge: 158 Beitrittsdatum: 12.12.11 Neueste Beiträge
Kyle Joseph Stiemann
Excuse me. It appeared that I use AUI 1.5 and there is no setAttribute there. At the same time you showed an instance of AUI 2.0. That is why we did not understand each other.
Excuse me. It appeared that I use AUI 1.5 and there is no setAttribute there. At the same time you showed an instance of AUI 2.0. That is why we did not understand each other.
Kyle Joseph Stiemann, geändert vor 9 Jahren.
RE: How to put the attribute "data-userId"
Liferay Master Beiträge: 760 Beitrittsdatum: 14.01.13 Neueste Beiträge
When I test the code with AlloyUI 1.5 it also works. Perhaps there's a js error in your code.
@David,
The docs for AlloyUI 1.5 recommend Node.setAttribute() for custom attrs, and specify that Node.setData() will not affect the DOM node. I don't know if that changed in other versions though.
- Kyle
@David,
The docs for AlloyUI 1.5 recommend Node.setAttribute() for custom attrs, and specify that Node.setData() will not affect the DOM node. I don't know if that changed in other versions though.
- Kyle
David H Nebinger, geändert vor 9 Jahren.
RE: How to put the attribute "data-userId"
Liferay Legend Beiträge: 14919 Beitrittsdatum: 02.09.06 Neueste Beiträge
@Kyle: Nuts
Actually I had gotten there from a different path, was working through the source for the aui:nav-item tag where the getData() is used vs getAttribute() and online stuff saying it's preferred because it clearly signifies intents...
Ah, well, thanks for following up.
Actually I had gotten there from a different path, was working through the source for the aui:nav-item tag where the getData() is used vs getAttribute() and online stuff saying it's preferred because it clearly signifies intents...
Ah, well, thanks for following up.
l ll, geändert vor 8 Jahren.
RE: How to put the attribute "data-userId" (Antwort)
Regular Member Beiträge: 158 Beitrittsdatum: 12.12.11 Neueste Beiträge
Thanks for the answer.
Will be correct:
Will be correct:
getData('userId');
and
setData('userId',1111);