从HTML删除标签 [英] Delete Label from HTML

查看:99
本文介绍了从HTML删除标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想从具有JavaScript的表class ="variations"中删除标签,该标签的属性为='pa_cb5feb1b7314637725a2e7'

I want DELETE only from table class="variations" with javascript the label which has attribute for = 'pa_cb5feb1b7314637725a2e7'

<table class="variations">
    <tbody> 
        <tr>
            <td class="label"><label for="pa_1ef722433d607dd9d2b8b7">Ships From</label></td>
        </tr>
        <tr>
            <td class="label"><label for="pa_cb5feb1b7314637725a2e7">Color</label></td>
        </tr>
    </tbody>
</table>

我只想保留发件人"; 感谢您的帮助

I WANT TO KEEP only "Ships From"; Any help is appreciated

推荐答案

只需在最后制作一个Script标记,然后获取带有label标记的所有元素,然后删除与您想要的for属性相同的元素.这是可能有用的代码-

Just Make a Script tag in the last and get all element with label tag and delete the element which has the same for attribute as you want. Here is the Code that might help -

<html>
<body>
<table class="variations">
    <tbody> 
        <tr>
            <td class="label"><label for="pa_1ef722433d607dd9d2b8b7">Ships From</label></td>
        </tr>

        <tr>
            <td class="label"><label for="pa_cb5feb1b7314637725a2e7">Color</label></td>
       </tr>
   </tbody>
</table>
<script>
   var labeltags = document.getElementsByTagName("label");
   for (var i=0;i<labeltags.length;i++){
       if (labeltags[i].getAttribute("for")=="pa_cb5feb1b7314637725a2e7"){
           labeltags[i].remove();
       }
   }
</script>    
</body>
</html>

这篇关于从HTML删除标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆