是否可以删除php或jquery中的<img>中的<a>而不直接在php中删除<a>?

I want to remove the <a> tag that is wrapped around the <img> tag. No link, only the image show up, no <a> html tag at all. But, without remove the <a>directly in php

I tried using css a{display:none;}, but that will remove everything. Do you think is that possible to do what I ask in PHP?

See the code below.

<a href=""> <img src="" /> </a>

</div>

is a server side language. Unless you are planning to pass your entire HTML code to PHP, it most likely will not achieve what you are trying to do.

On the other hand, there are several ways which you can do it in . One way to do it is to call unwrap() on the img element.

$("img").unwrap();

This will remove the parent a element.

You should use jquery.unwrap

<script>
   $(document).ready(function(){

     $("img").each(function(){
         var parent = $(this).parent();
         if(parent.is("a")){ //Remove only if the parent is "a" tag
            $(this).unwrap();
         }
     });
   });

</script>

You can chain contents() into unwrap():

contents() will return all the children of , including nodes, and unwrap() can be applied to nodes.

Use : $("a").contents().unwrap();