0

If a link is pressed on my startpage a jQuery Colorbox opens with my new site.

<script type="text/javascript">    
        $(document).ready(function(){        
            $(".deletealbum").each(function(){         
                $(this).click(function(event){
                    event.preventDefault();
                    var albumname = $(this).attr('name');
                    alert(albumname);               
                    $.post('deleteAlbum.php',
                    {
                        albumname: albumname
                    });                                       
                });
            });
        });   
    </script>

This is my Javascript - Code and below I have links, which look this way

echo "<a href='#' class='deletealbum' id='$Album' name='$Album'> DELETE </a>";

If I press the button, nothing happens in my colorbox, but if i include this page on my start page it works just perfectly.

So why doesn't it work in the colorbox ?

2 Answers2

0

Does your Colorbox thing use an iFrame? Your snippet may not add the event handlers on the elements you're willing to add them on in that case.

Pierre Voisin
  • 661
  • 9
  • 11
0

Run this code and see if you get an error message.

$(function () {
    var selector = ".deletealbum";
    var $el = $(selector);
    if (!$el.length) {
        var errMsg = "Error can't find '" + selector + "'";
        throw new Error(errMsg);
    }
    $el.click(function (e) {
        var albumname = $(e.target).attr('name');
        $.post('deleteAlbum.php', {
            albumname : albumname
        });
        return false;
    });
}());

If you get an error message then you're going to have to find the frame id which has the element you want. You should be able to find element within iframes and frames using $( window.frame[ id ] ).find( selector ).

Here's a link for more information.

How can I get an element from within a frameset frame using JavaScript?

Javascript - Get element from within an iFrame

I would inspect your html with firebug to speeedup the process.

Community
  • 1
  • 1
Larry Battle
  • 9,008
  • 4
  • 41
  • 55
  • Thank you, but I don´t get an error message. It seems like there isn´t any javascript on this page. (It is there, i checked it in the colorbox) – user1124288 Apr 09 '12 at 15:22