开发者

jQuery: testing for existence of something

开发者 https://www.devze.com 2023-03-22 00:57 出处:网络
Newbie alert... I\'m trying to make an educational that uses different audio players (with different ids) depending on the browser.In some cases, the div ids 开发者_Python百科will be #f-FIVE, for exa

Newbie alert...

I'm trying to make an educational that uses different audio players (with different ids) depending on the browser. In some cases, the div ids 开发者_Python百科will be #f-FIVE, for example, or, in other cases just #FIVE. This is not something I have a lot of control over due to the audio players.

Using jQuery, I want to use the div ids to test for which audio player is being used.

In this fiddle http://jsfiddle.net/eft84/15/, I am trying (unsuccessfully) to fade out an element using an if then structure if #f-FIVE exists. Would you be kind enough to help me spot my errors.


Here you go: http://jsfiddle.net/Paulpro/SySRb/

$('#f-FIVE').length

Will be 1 or more if there is a match (Should be exactly one since it's an id selector). If there is no match it will be 0 and evaluate to false.


With jQuery, you can check if the result of a selector is empty like this:

if ($("#f-FIVE").length) {
    // do something
}


I don't understand what the IF should do? I corrected the code below.

$(document).ready(function() {
    init();
});

function init() {
    var x = true; //#f - FIVE
    if (x === true) {
        $('#f-FIVE, #f-SIX').hide(1000);
    } else {
        return;
    }



}
0

精彩评论

暂无评论...
验证码 换一张
取 消