[英]Using SVG icons with jQuery toggle
I'm using a jQuery toggle for a show/hide button. 我正在使用jQuery切换按钮作为显示/隐藏按钮。 Is there a way to incorporate SVG icons (in this case, Octicons)? 是否可以合并SVG图标(在这种情况下为Octicons)?
$(function () {
$('.show-button').click(function(){
$(this).text(function(i,old){
return old=='Show less' ? 'Show more {% octicon chevron-down height:25 class:"right left" aria-label:toggle %}' : 'Show less';
});
});
});
Right now, this outputs: 现在,输出:
[ Show more <svg height="25" class="octicon octicon-chevron-down right left" aria-label="toggle"...]
Thank you! 谢谢!
Because you are setting text . 因为您正在设置文本 。 Consider using html instead. 考虑改用html 。
Additionally, I do not know what your base element is, but having svg's inside buttons or inputs might not be ideal. 另外,我不知道您的基本元素是什么,但是使用svg的内部按钮或输入可能并不理想。 So you might want to use a button-looking span if you want to adhere to the standards. 因此,如果您要遵守这些标准,则可能需要使用看起来像按钮的跨度。
你可以试试!
$(function () { $('.show-button').click(function(){ $(this).html(function(i,old){ return old=='Show less' ? 'Show more {% octicon chevron-down height:25 class:"right left" aria-label:toggle %}' : 'Show less'; }); }); });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.