我有一個圖像包含在我的html中的img標籤。它是與類「圖像」的div的內部。裏面的div是「caption」類的另一個div。該「標題」div包含一個段落。如何使用JavaScript或jQuery自動刪除內容
如何刪除「caption」div中的段落,並使用javascript或jQuery刪除「caption」div本身?
/* Script to delete the paragraph and caption div. */
$(".image img").each(function() {
var $this = $(this),
getClass = $this.attr('img')
splitClass = $this.prop('id').split("-")
if (splitClass[1] <= 20) {
$this.attr("src", "http://lorempicsum.com/futurama/350/200/1");
} else if (splitClass[1] >= 40) {
$this.attr("src", "http://www.top13.net/wp-content/uploads/2014/11/4-small-flowers.jpg");
} else {
$this.attr("src", "http://www.top13.net/wp-content/uploads/2014/11/4-small-flowers.jpg");
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="image">
\t <img id="img-1" src="http://www.top13.net/wp-content/uploads/2014/11/4-small-flowers.jpg" />
\t <div class="caption">
\t \t <p>DELETE THIS TEXT!</p>
\t </div>
</div>
<div class="image">
\t <img id="img-2" src="http://www.top13.net/wp-content/uploads/2014/11/4-small-flowers.jpg" />
\t <div class="caption">
\t \t <p>DELETE THIS TEXT!</p>
\t </div>
</div>
此外,我怎麼能使用jQuery下線?我必須下載它嗎?我怎麼做?
謝謝。
document.querySelector( '標題')的頭內取出()。 – Federico
https://jquery.com/download/ – Federico
@Federico在哪裏放? –