1

I would like to remvoe img tag and change css class of span tag through jquery. and I would like to delete using ID's. I tried using this code Delete a div or span with a id=".xxx" but it didn't work

  <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>
Community
  • 1
  • 1
dotnetrocks
  • 2,589
  • 12
  • 36
  • 55
  • Unrelated, but having and ID this long means you need to switch a CMS, and fast. And if it's not a CMS, then may [Cthulhu](http://en.wikipedia.org/wiki/Cthulhu) mercy your soul. – Madara's Ghost Dec 18 '11 at 18:48
  • @Truth It's a standard ID structure for ASP.Net Forms, each element gets 'namespaced' by any containers with IDs. – robertc Dec 18 '11 at 21:24

4 Answers4

1

Like this?

$("#ctl00_objContentPageTag_spzContactInformation_txt_sContactZipCode_spanImgMandatory").remove();
$("#ctl00_objContentPageTag_spzContactInformation_txt_sContactZipCode_imgMandatory").addClass("class_name");
Madara's Ghost
  • 172,118
  • 50
  • 264
  • 308
inlanger
  • 2,904
  • 4
  • 18
  • 30
  • Please format your code properly. A code block is inserted by indenting 4 spaces before any line of code. I've formatted the code for you this time, but please format it properly next time. For further help, see the [Editing FAQ](http://stackoverflow.com/editing-help#code) – Madara's Ghost Dec 18 '11 at 18:52
1
$("#ctl00_objContentPageTag_spzContactInformation_txt_sContactZipCode_spanImgMandatory img").remove();
$("#ctl00_objContentPageTag_spzContactInformation_txt_sContactZipCode_spanImgMandatory").addClass("newClass");
Dominic Green
  • 10,142
  • 4
  • 30
  • 34
1

Try this:

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

[change myid and newclass to suit].

Note that this will remove all children of the specified span. If you really only want to delete IMG tags use this instead:

$('#myid').addClass('newclass').children('img').remove();
Alnitak
  • 334,560
  • 70
  • 407
  • 495
1

Try something like this:

$('#your-span-id').addClass('some-class').find('img').remove();
Marek Příhoda
  • 11,108
  • 3
  • 39
  • 53