简体   繁体   中英

Uncaught TypeError: undefined is not a function :/

Hi I am stuck on this error for a while and can't seem to find where the problem comes from... I am basically dynamically making multiple list items with buttons in them for each row in my database with php:

<div id="upgrades">
            <ul>
                <?php
                for($i=0;$i<count($_SESSION['upgrades']);$i++)
                {
                    $class = '';
                    if($_SESSION['upgrades'][$i]['gekocht'] == TRUE)
                    {
                        $class = 'gekocht';
                    }
                    echo '
                    <li>
                    <button class="upgradebutton'.$class.'" data-id="'.$_SESSION['upgrades'][$i]['update_id'].'">'.$_SESSION['upgrades'][$i]['naam'].'</button>
                    </li>';
                }
                ?>
            </ul>
        </div>

And then check if it has that class I append to it when the upgrade is already bought on each button click with javascript:

$(document).ready(function(){   
$('.upgradebutton').click(function(){
    if(!$(this).hassClass('upgradebuttongekocht'))
    {
        var upgrade_id = $(this).attr("data-id");
        alert(upgrade_id);
        $(this).addClass('gekocht');
        window.upgrades[upgrade_id][gekocht] = 1;
    }else{
        alert("already Bought");
    }
});
});

Just use hasClass instead of hassClass

http://api.jquery.com/hasclass/

:)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM