Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.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
Jquery 删除子级并更改父级的css类_Jquery_Css - Fatal编程技术网

Jquery 删除子级并更改父级的css类

Jquery 删除子级并更改父级的css类,jquery,css,Jquery,Css,我想删除img标记,并通过jquery更改span标记的css类。我想用ID删除。我试着用这个代码,但没有用 <span id="ctl00_objContentPageTag_spzContactInformation_txt_sContactZipCode_spanImgMandatory" class="xqh_LookUpTextBox_ImgMandatory"> <img id="ctl00_objContentPageTag_spzContactInfo

我想删除img标记,并通过jquery更改span标记的css类。我想用ID删除。我试着用这个代码,但没有用

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

像这样吗

$("#ctl00_objContentPageTag_spzContactInformation_txt_sContactZipCode_spanImgMandatory").remove();
$("#ctl00_objContentPageTag_spzContactInformation_txt_sContactZipCode_imgMandatory").addClass("class_name");
像这样

$("#ctl00_objContentPageTag_spzContactInformation_txt_sContactZipCode_spanImgMandatory").remove();
$("#ctl00_objContentPageTag_spzContactInformation_txt_sContactZipCode_imgMandatory").addClass("class_name");
试试这个:

$('#myid').addClass('newclass').empty();
[根据需要更改
myid
newclass

请注意,这将删除指定范围的所有子项。如果您真的只想删除
IMG
标记,请使用此选项:

$('#myid').addClass('newclass').children('img').remove();
试试这个:

$('#myid').addClass('newclass').empty();
[根据需要更改
myid
newclass

请注意,这将删除指定范围的所有子项。如果您真的只想删除
IMG
标记,请使用此选项:

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

试着这样做:

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

试着这样做:

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

不相关,但是有这么长的ID意味着你需要快速切换CMS。如果它不是一个CMS,那么可能会怜悯你的灵魂。@事实上,这是ASP.Net表单的标准ID结构,每个元素都会被任何ID为的容器“命名空间”。不相关,但有和ID这么长意味着你需要快速切换CMS。如果它不是CMS,那么可能会怜悯你的灵魂。@Truth这是ASP.Net表单的标准ID结构,每个元素都会被任何带有ID的容器“命名空间”。请正确设置代码格式。通过在任何代码行之前缩进4个空格插入代码块。这次我已经为您格式化了代码,但下次请正确格式化。有关更多帮助,请参阅“请正确设置代码格式”。通过在任何代码行之前缩进4个空格插入代码块。这次我已经为您格式化了代码,但下次请正确格式化。有关更多帮助,请参阅