2011-12-18 40 views
3

我想刪除所選元素的下一個元素。在這裏,我想用css類「xqh_Mandatory_icon」去除「div」。刪除下一個元素 - jquery

<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> 

我嘗試使用此代碼

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

,但沒有奏效。

回答

11
<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> 

設置在文檔就緒時,它執行的代碼,你也失蹤了第二類名的時期。你在那裏有一個空間。