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 ?

5
  • 1
    What's with the </img> in the middle of the <a> tag? Commented Apr 9, 2012 at 14:38
  • You don't need to use .each( to bind handlers to multiple elements. You can do $(".deletealbum").click( to bind to all of them. Commented Apr 9, 2012 at 14:39
  • @Pointy There was a picture in it, but that wasn´t the mistake unfortunately. Commented Apr 9, 2012 at 14:42
  • @Rocket This doesn´t work either.. Like I said, if i include the page on my start-page it works perfectly... So it´s just about the javascript in the colorbox ?! Commented Apr 9, 2012 at 14:44
  • @user1124288: I wasn't suggesting that as the solution, I was just pointing that out. Commented Apr 9, 2012 at 14:58

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

This could be the problem ! Can you tell me how does this work ?!
Did you have a look to Larry Battle's links?
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.

1 Comment

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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.