2013-05-27 52 views
-3
<div id="homePageBottomNewsWrapper"> 
    <div class="col1"> 
     <div class="homePage3ColsThumbPhoto"> 
     <p> 
      <img alt="" src="/Content/uploads/images/imgNews4.jpg"> 
     </p> 
    </div> 
</div> 

我想刪除這個p元素。我怎麼用jQuery來做到這一點?從特定的html頁面元素中刪除p段

更新:如果你想刪除整個p

$(".homePage3ColsThumbPhoto p") 
    .html() 
     .appendTo(".homePage3ColsThumbPhoto") 
    .end() 
    .remove(); 

$('img').unwrap(); 
+0

https://www.google.se/search?q=jquery+remove+element+stackoverflow&oq=jquery+remove+element+stackoverflow&aqs=chrome.0.57j60j62l3.3539j0&sourceid=chrome&ie=UTF-8 – Johan

回答

3

如果要刪除只是<p>標籤,而不是<img>或任意數量的元素,然後做到這一點標籤和內容可以做到這一點;

$(".homePage3ColsThumbPhoto p").remove(); 
1
$(".col1 p").remove(); 
//If you want to remove all the `p` elements in col1 

$(".homePage3ColsThumbPhoto p").remove(); 
//If you want to remove all the `p` elements in homePage3ColsThumbPhoto 

$("p").remove() 
//if you have only one `p` element 
0

嘗試,

$(function(){ 
    $(".homePage3ColsThumbPhoto p").remove(); 
}); 
0

有很多方法可以做到這一點

對於直接孩子

$(".homePage3ColsThumbPhoto>p").remove(); 

$(".homePage3ColsThumbPhoto p").remove(); //對於所有的後代。