开发者

Toggle removes text, show/hide keeps it

This isn't so much a question to help me figure out a problem as it is one to help me figure out why the fix I came up with works.

I have some elements on a page which are created with jquery after loading some data with ajax. I have a checkbox which is supposed to toggle the visibility of some of these elements. When I tried using JQuery's .toggle() function, the elements would disappear properly, but when they came back, they were empty!

I decided to try show/hide instead (based on the checkbox's value) and for some reason, it works perfectly! I don't understand why, though, and I was wondering if somebody could explain it to me, for future reference. Here is my code (working, with faulty stuff commented out):

$("#fbfeed").click(function(){
    //$(".fbcheckin").toggle(); // This killed my text.
    if($("#fbfeed").attr("checked")!="checked") $(".fbfeed").hide();
    else $(".fbfeed").show();
});

Thanks in advance for any responses! :-)

EDIT

I definitely forgot to mention something. The faulty code I left in the comment is actually technically valid in that there are ".fbcheckin" elements as well, that I'm also doing this to. I forgot to change it back before posting my code, but I switched the selector to see if I had the same problems with those elements. Which I did.

Sorry for the co开发者_如何学Pythonnfusion! :-\


It looks like you've been toggling the wrong div - try

$('#fbfeed').click(function(){
   $('.fbfeed').hide();
});

instead.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜