Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 删除特定的内联元素_Javascript_Jquery - Fatal编程技术网

Javascript 删除特定的内联元素

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

如何删除由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.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")