3

I'm trying to find an object in HTML with jQuery.

function getHats() {
    $.get('http://www.roblox.com/User.aspx?ID=1',
        function parse(data) {
            var id1 = $(data).find('#ctl00_cphRoblox_rbxUserAssetsPane_UserAssetsDataList_ctl09_AssetThumbnailHyperLink');
            hatname1 = id1.attr('title');
            hatlink1 = "http://www.roblox.com" + id1.attr('href');
            hatpic1 = id1.find('img').attr('src');
            var lim1 = id1.parent('.AssetThumbnail').find('div');
            if(!lim1) {
                hatlim1 = true;
                alert("Null")
            }else{
                hatlim1 = false;
            };
        }
    );
};

It always pops up the alert.

2 Answers 2

6

Use length - but you don't have to be explicit about it:

if (lim1.length) {
    // lim1 has a length! And it's not 0!
} else {
    // arg, lim1 has a length of 0
}

Equivalently, the negation operator ! will work fine.

if (!lim1.length) {
    // arg!
}
Sign up to request clarification or add additional context in comments.

Comments

3

In this case, you can use length.

if(lim1.length < 1){
    //alert 
}

Comments

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.