当用户点击该部分内的链接时,我正在尝试删除整个部分。任何帮助将不胜感激。
HTML: -
<section id = "intro">
<h1> Hey There!</h1>
<a href = "#" id = "button_intro"> Click here </a>
</section>
JQuery的:
$(document).ready(function(){
$("#button_intro").click(function(){
$("#intro").remove();
});
});
jQuery代码位于.js
文件中,该文件已按此链接
<script src = "script.js" async> </script>
答案 0 :(得分:1)
你有jquery库src吗?它完美地运作:
$(document).ready(function()
{
$("#button_intro").click(function()
{
$("#intro").remove();
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<section id = "intro">
<h1> Hey There!</h1>
<a href = "#" id = "button_intro"> Click here </a>
</section>
答案 1 :(得分:0)
您的代码有效。
我想你忘了加载jquery。
使用此脚本标记<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<section id = "intro">
<h1> Hey There!</h1>
<a href = "#" id = "button_intro"> Click here </a>
</section>
<script>
$(document).ready(function()
{
$("#button_intro").click(function()
{
$("#intro").remove();
});
});
</script>
&#13;