1

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 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.

satoru
  • 31,822
  • 31
  • 91
  • 141
Leahcim
  • 40,649
  • 59
  • 195
  • 334
  • 1
    possible duplicate of [Is there an "exists" function for jQuery](http://stackoverflow.com/questions/31044/is-there-an-exists-function-for-jquery) – Daniel A. White Jul 19 '11 at 22:40

3 Answers3

1

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.

Paul
  • 139,544
  • 27
  • 275
  • 264
1

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

if ($("#f-FIVE").length) {
    // do something
}
satoru
  • 31,822
  • 31
  • 91
  • 141
0

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;
    }



}
Mike
  • 144
  • 6