Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery .show() not working in firefox

I have a problem with the jquery show function in firefox.

Situation: I have loaded a iframe with an aspx page in a popup (fancybox). In that aspx page I have a button with an onclick event which calls a custom function and in that function it fires the .show() function on a div. This div has a style element which contains: display:none;.

This works in IE, safari, chrome. This even works in firefox when I load the aspx page standalone. It doesnt work in firefox in the fancybox-iframe popup. I get no javascript errors. Even the display:none is removed from the style attribute, but the div doesnt show up.

The html from the page

<div class="popupWrapper">
  ..some elements
  <div id="psharebutton" style="display:none;"> 
   ..content of the div
  </div>
</div>

The javascript code:

function dolinkedin(url, title, summary, source) {
        $(".smbutton").addClass("buttonDisabled");
        $("#linklinkedin").removeClass("buttonDisabled");
        $("#psharebutton").show();

        parent.sizeFancybox();
    }

The button where the popup is triggered, is a anchor, which has the fancyboxiframe class. Fancybox will automaticly generate the js code for showing the popup.

I have checked these topics:

  • Jquery Hide/Show not working in Firefox Only?
  • Jquery hide/show not working in Firefox/Chrome
  • Jquery .show() and .hide() or even .css({"display":"none"}); not working in firefox?

I have checked if my html is valid and it is.

Any idea?

BHD

like image 401
Maarten Kieft Avatar asked Sep 01 '11 08:09

Maarten Kieft


3 Answers

I had a similar problem and my solution was to do

$("#psharebutton").css("display", "inline-block");

instead of

$("#psharebutton").show();

A jquery "show" is identical to setting the display style attribute to "block". I found that I needed "inline-block" for firefox and chrome (I didn't need this for IE). I believe (but have not confirmed) that jquery is smart enough to know what the previous display value is and use that, but in my case I started out with display set to "none" so there was no previous value.

like image 134
Kirk Liemohn Avatar answered Oct 31 '22 17:10

Kirk Liemohn


Just write down like $("#psharebutton").attr('display','') or $("#psharebutton").attr('display','block').

function dolinkedin(url, title, summary, source) {
        $(".smbutton").addClass("buttonDisabled");
        $("#linklinkedin").removeClass("buttonDisabled");
        $("#psharebutton").attr('display','');

        parent.sizeFancybox();
    }
like image 22
DJ. Avatar answered Oct 31 '22 17:10

DJ.


I had a similar problem. I did set this in my css:

body { display: none }

and tried to change this in jQuery:

$("body").show();

which did not work in Firefox.

After I changed the HTML to

<body style="display: none">

and removing the part from CSS I was able to use jQuery show(); flawless

It seems that the inheritance of css rules does not follow the same routine in Firefox as in IE / Chrome.

like image 1
Markus Bucher Avatar answered Oct 31 '22 15:10

Markus Bucher