2011-12-18 41 views
1

我想通過jquery提交img標籤並更改span標籤的css類。我想刪除使用ID的。我嘗試使用此代碼Delete a div or span with a id=".xxx",但沒有奏效刪除孩子,並更改父類的css類

<span id="ctl00_objContentPageTag_spzContactInformation_txt_sContactZipCode_spanImgMandatory" class="xqh_LookUpTextBox_ImgMandatory"> 
    <img id="ctl00_objContentPageTag_spzContactInformation_txt_sContactZipCode_imgMandatory" src="/spzBaseModule/Look_Base/Images/Admin/Icons/iconMandatory8x14.png" style="border-width:0px;align:middle;"> 
    </span> 
+0

無關,但有和ID這漫長意味着你需要切換一個CMS和快速。如果它不是CMS,那麼[Cthulhu](http://en.wikipedia.org/wiki/Cthulhu)可能會憐憫你的靈魂。 – 2011-12-18 18:48:40

+0

@Truth它是ASP.Net Forms的一個標準ID結構,每個元素都通過任何帶有ID的容器獲得「命名空間」。 – robertc 2011-12-18 21:24:35

回答

1

試試這個:

$('#myid').addClass('newclass').empty(); 

[變化myidnewclass適合。

請注意,這將刪除全部指定範圍內的子女。如果你真的只想要刪除IMG標籤使用這個代替:

$('#myid').addClass('newclass').children('img').remove(); 
1

喜歡這個?

$("#ctl00_objContentPageTag_spzContactInformation_txt_sContactZipCode_spanImgMandatory").remove(); 
$("#ctl00_objContentPageTag_spzContactInformation_txt_sContactZipCode_imgMandatory").addClass("class_name"); 
+0

請正確格式化您的代碼。通過在任何代碼行之前縮進4個空格來插入代碼塊。我這次爲您編寫了代碼格式,但下次請正確格式化。如需進一步的幫助,請參閱[編輯常見問題](http://stackoverflow.com/editing-help#code) – 2011-12-18 18:52:40

1
$("#ctl00_objContentPageTag_spzContactInformation_txt_sContactZipCode_spanImgMandatory img").remove(); 
$("#ctl00_objContentPageTag_spzContactInformation_txt_sContactZipCode_spanImgMandatory").addClass("newClass"); 
1

嘗試是這樣的:

$('#your-span-id').addClass('some-class').find('img').remove();