admin管理员组文章数量:1434916
I have the following button element in my HTML
<button id="play-pause" aria-hidden="true"></button>
On the jQuery ready event, I run the following code:
$('#play-pause').attr('data-icon', '')
That turns the HTML element into this
<button id="play-pause" aria-hidden="true" data-icon=""></button>
Which renders like this in the browser (Chrome stable):
However, if I delete the JavaScript code, manually change the HTML to the following (it's the same thing as the JS waas doing) and refresh the page:
<button id="play-pause" aria-hidden="true" data-icon=""></button>
then it renders like this:
What's the difference?
I suspect it's irrelevant but here's the CSS:
/* Use the following CSS code if you want to use data attributes for inserting your icons */
[data-icon]:before {
font-family: '45sound';
content: attr(data-icon);
speak: none;
font-weight: normal;
font-variant: normal;
text-transform: none;
line-height: 1;
font-style:normal;
}
I have the following button element in my HTML
<button id="play-pause" aria-hidden="true"></button>
On the jQuery ready event, I run the following code:
$('#play-pause').attr('data-icon', '')
That turns the HTML element into this
<button id="play-pause" aria-hidden="true" data-icon=""></button>
Which renders like this in the browser (Chrome stable):
However, if I delete the JavaScript code, manually change the HTML to the following (it's the same thing as the JS waas doing) and refresh the page:
<button id="play-pause" aria-hidden="true" data-icon=""></button>
then it renders like this:
What's the difference?
I suspect it's irrelevant but here's the CSS:
/* Use the following CSS code if you want to use data attributes for inserting your icons */
[data-icon]:before {
font-family: '45sound';
content: attr(data-icon);
speak: none;
font-weight: normal;
font-variant: normal;
text-transform: none;
line-height: 1;
font-style:normal;
}
Share
Improve this question
asked May 21, 2013 at 23:05
David TuiteDavid Tuite
22.7k25 gold badges115 silver badges179 bronze badges
1
- are you using jquery UI buttons? – km6zla Commented May 21, 2013 at 23:12
1 Answer
Reset to default 7Use Unicode value:
$('#play-pause').attr('data-icon', '\uE00A');
本文标签: jquerySetting element dataicon with JavaScriptStack Overflow
版权声明:本文标题:jquery - Setting element data-icon with JavaScript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745616980a2666459.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论