b4rbika
b4rbika

Reputation: 157

Javascript/Jquery code skips whole function in debugger

function bet() {
    $('table img').css('cursor', 'pointer');
    $('table img').click(function () {
        yourBetNumber = $(this).slice(0, -1);       
        $('#item' + yourBetNumber).clone().appendTo('#yourbet');
        $('table').hide();
        $('table img').css('cursor', 'pointer');
    });
}

I have a table of items displayed, each item is a different image and has a unique ID in the html. What I'm trying to do is enable the user to click on the item they want to bet on and that should be registered as their bet number. I'm not sure the slice part is correct yet, but that's not the point - the function isn't executed at all even though I call it in the code. The debugger also just skips over it entirely when I try to step into the next line (tried with breakpoints etc).

Any idea why this happens and how it could be fixed please?

Upvotes: 0

Views: 900

Answers (2)

nrsharma
nrsharma

Reputation: 2562

You need to call bet() within the document.ready Try this

$('document').ready(function () {
    bet();
});

Upvotes: 1

alexP
alexP

Reputation: 3765

function bet(el) {
    var yourBetNumber = $(el).slice(0, -1);
    $('#item' + yourBetNumber).clone().appendTo('#yourbet');
    $('table img').hide();
}

//Setting the CSS
$(document).ready(function () {
    $('table img').css('cursor', 'pointer');
});

//AddEventHandler
$('table img').click(function () {
    bet($(this)); //Call Function "bet" with the jQuery-Object
});

Upvotes: 0

Related Questions