how to remove anchor tag from div which doesnt have any id or class using jquery?


My demo here

i had code to remove a tag with id or class ..But in this case the anchor tag is generated by wordpress as attachment and it doesnt have any id,class

ANCHOR TAG looks like this

<a rel="attachment wp-att-107 slb_group[344] slb slb_internal" 
href="" >

Jquery ATTEMPTS made


but this function requires class or id of anchor tag which is absent here...


<div id="imgContnr">

I want to remove anchor tag inside div with id imgContnr

I have using css by making pointer-events:none; but it will affect all the anchor tags which is not right .. Somehow i want it to happen using jquery ..Plz look into it ..

Problem courtesy of: Vaibs_Cool


Try this:

$("#imgContnr a").remove();

This will remove anchor tags whose parent is imgContnr.


Sorry, I misunderstood what you're trying to acheive. Although Just-lewis' answer works perfect, I'll post my alternative answer to that anyway. This code works the same except it's much shorter

Solution courtesy of: Jude Duran


if your removing the tag all together Jude is correct but if you trying to keep the elements within it'll be as follows:


   keeping = $(this).html();


Heres your demo edited

Discussion courtesy of: Just-lewis

This recipe can be found in it's original form on Stack Over Flow.