删除下一个元素 - jquery

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8552520/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 10:41:01  来源:igfitidea点击:

remove next element - jquery

jqueryhtml

提问by dotnetrocks

I would like remove next element of a selected element. Here, I would like to remove "div" with css class "xqh_Mandatory_icon".

我想删除所选元素的下一个元素。在这里,我想用 css 类“xqh_Mandatory_icon”删除“div”。

<div class="xqh_Field">
    <nobr>
     <input name=
    "ctl00$objContentPageTag$spzContactInformation$txt_sContactFirstName$txt" type="text"
    size="25" id=
    "ctl00_objContentPageTag_spzContactInformation_txt_sContactFirstName_txt" class=
    "xqh_TextBox_Edit validate_txt_sContactFirstName" style=
    "width:150px;margin-right:0px;" />
     </nobr>
     <div class="xqh_Mandatory_icon"></div>
</div>

I tried with this code

我试过这个代码

$('.xqh_TextBox_Edit.validate_txt_sContactFirstName').next().remove('xqh_Mandatory_icon');

but it didn't work.

但它没有用。

回答by John

<html>
<head>
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
            $('.xqh_TextBox_Edit.validate_txt_sContactFirstName').next().remove();
        });
    </script>
</head>
<body>
    <div class="xqh_Field">
        <input name="ctl00$objContentPageTag$spzContactInformation$txt_sContactFirstName$txt"      type="text" size="25"               id="ctl00_objContentPageTag_spzContactInformation_txt_sContactFirstName_txt"     class="xqh_TextBox_Edit validate_txt_sContactFirstName" style="width:150px;margin-right:0px;">     
        <div class="xqh_Mandatory_icon">
            yep
        </div>
    </div>
</body>
</html>

Set it to execute the code when the document is ready, also you were missing the period for the second class name. You had a space there instead.

将其设置为在文档准备好时执行代码,同时您也缺少第二个类名的句点。你在那里有一个空间。