我有一些加載在我的網站上的文本,帶有jQuery方法load()。點擊外部加載內容的功能
我想關閉(空())我點擊h2時加載的div。
我的HTML:
<html>
<div class="info_item" id="post1">
<div name="x" class="item" id="loaded_with_ajax">
<h2>Click on this h2 should empty the div with class="item"</h2>
<h3>this is a h3</h3>
<p>this is a paragraph</p>
</div>
</div>
</html>
我的jQuery;
$("h2").on('click', function() {
$(this).parent("div").empty();
});
也許我的代碼是錯誤的,但即使我把在點擊H 2的警報(),所加載的內容,它不反應。
在此先感謝。
使用$(本).parent( 「格」)文本( 「」)。 – Dineshkani
不改變任何東西:(這就像點擊功能沒有應用在加載的內容.. –
看到這個小提琴http://jsfiddle.net/Dineshkani/pj4tp/。調用你的jQuery代碼在onload或$(文檔).ready(function(){// Your code}); – Dineshkani