how to hide link when content is empty?
I have created a example here: http://jsfiddle.net/zidski/TFBqf/7/
This is not working:
var a = $("#content div:empty").html("").css("background","red");
if(a) {
$("#link").hide;
}else{
$("#link").sho开发者_运维百科w;
return;
}
You're not actually executing the .show
and .hide
methods...
Should be:
if(a) {
$("#link").hide();
}else{
$("#link").show();
return;
}
if(a) {
$('#link').hide(); // instead of .hide;
}else{
$('#link').show(); // instead of .show;
return;
}
Here is: http://jsfiddle.net/TFBqf/18/
try to remove text in div to check it
var a = $("#content div").html("");
if(a.length == 0) {
$("#link").hide();
}
Check this: http://jsfiddle.net/TFBqf/14/
You were actually checking the wrong thing and use the show
method for both cases (without the use of parenthesis also).
var a = $("#content div").html();
This will return the actual content of your div.
Works:
$('#link')[$('#content:empty').length ? 'show' : 'hide']();
精彩评论