Javascript 删除特定的内联元素
如何删除由JS添加的特定内联样式。我一直在研究这个样本。不幸的是仍然没有成功Javascript 删除特定的内联元素,javascript,jquery,Javascript,Jquery,如何删除由JS添加的特定内联样式。我一直在研究这个样本。不幸的是仍然没有成功 <a id="mylink" style="color:red; font-weight:bold" href="http://www.website.com">go to somesite.com</a> 根据我的要求,我想使用jquery删除“font-weight:bold” <script> function myFunction() { document.g
<a id="mylink" style="color:red; font-weight:bold"
href="http://www.website.com">go to somesite.com</a>
根据我的要求,我想使用jquery删除“font-weight:bold”
<script>
function myFunction() {
document.getElementById("mylink").style.removeAttribute('font-weight:bold');
}
函数myFunction(){
document.getElementById(“mylink”).style.removeAttribute('font-weight:bold');
}
使用jquery:
$('#mylink').css('font-weight','');
使用jquery:
$('#mylink').css('font-weight','');
removeAttribute
不起作用,因为font-weight:bold
是一种样式而不是属性。要删除/取消设置此项,我建议使用:
removeAttribute
不起作用,因为font-weight:bold
是一种样式而不是属性。要删除/取消设置此项,我建议使用:
如何从样式中删除该属性如何从样式中删除该属性style@Chris,为编辑喝彩,我对被接受的答案感到惊讶,因为他们要求jquery解决方案:D@Chris,为编辑喝彩,我对被接受的答案感到惊讶,因为他们要求一个jquery解决方案:D
document.getElementById("mylink").style.removeProperty("font-weight")