问题
I am reading jQuery, i don't know why use ("*")
please explain it's helpful
<script>
$(document).ready(function(){
$("button").click(function(){
$("*").hide();
});
});
</script>
回答1:
*
is a selector in jquery which select everything without any condition including html, head and body.
Here is an example explaining its usage.
$(document).ready(function(){
$("button").click(function(){
$("*").hide();
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
Hello text
</div>
<button>Click Me to Hide everything</button>
$(document).ready(function(){
$("button").click(function(){
$("div *").toggle();
});
});
div{
border:0.5px solid red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
<p>Hello text</p>
<a>Here is a link </a>
</div>
<button>Click Me to Hide/ Show elements inside the div</button>
回答2:
$(*)
is used to select all elements inside the document. Refer this: https://www.w3schools.com/jquery/sel_all.asp
回答3:
$(*)
is a selector in jqueryto select all elements
and hence
$("*").hide();
will hide all elements
$(document).ready(function(){
$("button").click(function(){
$("*").hide();
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>Hello</div>
<p>World</p>
<span>Good Morning</span>
<button>Hide</button>
Docs
来源:https://stackoverflow.com/questions/43153792/what-is-the-use-of-in-jquery