Close jQuery thickbox on button click

12,523

Solution 1

Thickbox have their built in method. tb_remove just call this method tb_remove(); wherever you need. It will close thickbox properly.

If you use $('#TB_window').fadeOut(); , TB_overlay DIV will remain open. If you again do something nonsense like $('#TB_overlay').fadeOut(); then it will create problem for your thickbox. And thickbox will stop function.

Solution 2

This solution worked for me, try it:

$(document).ready(function{
  $('#button').click(function(){
   self.parent.tb_remove();
  });
});

Solution 3

You have to prevent the execution of the default event of the input. Change your code to this:

$('#button').click(function(){
     $('#TB_window').fadeOut();
     e.preventDefault();
});

Solution 4

If you are including thickbox.js, which is obvious, than try.....

$('#closeTBWindow').click(tb_remove);
Share:
12,523

Related videos on Youtube

sudeep cv
Author by

sudeep cv

I am simply a human with emotions, needs, fears. I have a past and a future. I am far from perfect and I am not the worst failure in the world either!!!

Updated on September 15, 2022

Comments

  • sudeep cv
    sudeep cv over 1 year

    Here is my jQuery:

    <script src="../js/jquery.min.js"></script>
    <script type="text/javascript" src="../js/thickbox.js"></script>
    <script type="text/javascript"
    
    $('#button').click(function(){
         $('#TB_window').fadeOut();
    });
    
    </script>
    

    Html:

      <input type="submit" id="button" value="clse" >
    

    I tried this function, but it's not working.

    • Makarand Mane
      Makarand Mane about 10 years
      Thickbox have their built in method. tb_remove just call this method tb_remove(); wherever you need. It will close thickbox properly. read more my answer written below . stackoverflow.com/a/21216272/1124612
  • Jezen Thomas
    Jezen Thomas almost 12 years
    Probably better if you use an e.preventDefault(). Stop misusing return false.
  • Kash
    Kash over 5 years
    One line to do it: $('#TB_window, #TB_overlay').fadeOut();
  • Kash
    Kash over 5 years
    I love this sloution because it allows to reopen if clicked. the updated code should be: $('#TB_closeWindowButton').click();
  • Typel
    Typel almost 5 years
    Note that if modal=true, tb_remove() should be called from within the thickbox content. For example, <div id="myThickbox"><button onclick="tb_remove();">X</button></div> .