[英]Javascript - Change button text doesn't work
I have the following piece of code I need in order to update a bootstrap button when a collapsed is opened or closed.我需要以下代码,以便在打开或关闭折叠时更新引导按钮。 However the icon part is updating but impossible to get the button text updated and I have no idea why.然而,图标部分正在更新,但无法更新按钮文本,我不知道为什么。
My javascript level is very low and I'm simply using part of code I might find on SOF or anywhere else on inte.net.我的 javascript 水平很低,我只是使用了我可能在 SOF 或 inte.net 上其他任何地方找到的部分代码。
Javascript Javascript
$('#more-properties').on('hidden.bs.collapse', function () {
var icon = document.getElementById("icon-more-properties");
icon.setAttribute('class', 'fas fa-angle-down pr-2');
var btn = document.getElementById("btn-more-properties");
btn.textContent('More properties');
});
$('#more-properties').on('shown.bs.collapse', function () {
var icon = document.getElementById("icon-more-properties");
icon.setAttribute('class', 'fas fa-angle-up pr-2');
var btn = document.getElementById("btn-more-properties");
btn.textContent('Less properties');
});
Bootstrap button引导按钮
<div class="col-12 text-center" id="btn-div">
<button class="btn btn-outline-dark shadow-none collapsed" id="btn-more-properties" type="button" data-toggle="collapse" data-target="#more-properties" style="border-radius: 0 !important;">
<i id="icon-more-properties" class="fas fa-angle-down pr-2"></i>More properties</button>
</div>
Does anyone can tell me why it is not working?有谁能告诉我为什么它不起作用? I can't find any similar issue on ite.net.我在 ite.net 上找不到任何类似的问题。
Thank you in advance for your help.预先感谢您的帮助。
that textContent
is not a function but a property, so instead of calling it you need to assign the value to it: textContent
不是 function 而是一个属性,因此您需要为其分配值而不是调用它:
btn.textContent = 'Less properties';
Hope this helps希望这可以帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.