admin管理员组文章数量:1291024
I have the following code.
<li class="source" data-toggle="tooltip" data-placement="top" id="content1" title="" data-original-title="Test">Test Server 1</li>
I'm trying to change the content of data-original-title using the following code:
document.getElementById('content1').style["data-original-title"] = 'Online';
Am I doing something wrong?
I have the following code.
<li class="source" data-toggle="tooltip" data-placement="top" id="content1" title="" data-original-title="Test">Test Server 1</li>
I'm trying to change the content of data-original-title using the following code:
document.getElementById('content1').style["data-original-title"] = 'Online';
Am I doing something wrong?
Share Improve this question asked Nov 9, 2015 at 19:16 Dr. BananaDr. Banana 4351 gold badge7 silver badges19 bronze badges5 Answers
Reset to default 5You can use .dataset
document.getElementById('content1').dataset.originalTitle = 'Online';
<li class="source" data-toggle="tooltip" data-placement="top" id="content1" title="" data-original-title="Test">Test Server 1</li>
or .setAttribute
document.getElementById('content1').setAttribute('data-original-title', 'Online');
<li class="source" data-toggle="tooltip" data-placement="top" id="content1" title="" data-original-title="Test">Test Server 1</li>
data-original-title
is an attribute, so you would need to set it as such:
document.getElementById('content1').setAttribute('data-original-title','Online');
use setAttribtute()
document.getElementById("content1").setAttribute("data-original-title", "Online");
Try this one:
document.getElementById('content1').dataset.originalTitle = 'Online';
<li class="source" data-toggle="tooltip" data-placement="top" id="content1" title="" data-original-title="Test">Test Server 1</li>
This does not seem to be a style, try this:
document.getElementById('content1').data-original-title = 'Online';
本文标签: change html attribute with javascriptStack Overflow
版权声明:本文标题:change html attribute with javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741516017a2382894.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论