Is there some one can help me about this? If the page contains id = "item1" executes #home.hide(); I am really frustrated about this. My code:
<tr>
<td id = "item1">
</tr>
if($("body:has(#item1)")){
$('#home').hide();
}
If what you're trying to do is to execute $('#home').hide();
only if the #item1
object is present, then you would do that like this:
if ($("#item1").length > 0) {
$('#home').hide();
}
There is no need for checking if #item1
is in body
since that's the only place it can be. You can simply just check for #item1
since ids must be unique.
You could even resort to plain JS for the condition as an illustration of how simple it is:
if (document.getElementById("item1")) {
$('#home').hide();
}
If that isn't what you're trying to do, then please clarify your question further.
All you need is:
<script type="text/javascript">
$(function() {
if($("#item1").length) {
$('#home').hide();
}
});
</script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With