ehime
ehime

Reputation: 8375

JQuery syntax error for init

Hey guys I'm getting a syntax error on my var url line but I can't seem to figure out what or why it is, help appreciated

SW.wmode = {
    init: function() {
    $('iframe').each(function()
        var url = $(this).attr("src")
        $(this).attr("src",url+"?wmode=transparent")
        );
    }
}

Upvotes: 0

Views: 203

Answers (5)

Šime Vidas
Šime Vidas

Reputation: 185933

I refactored your code a bit:

SW.wmode = {
    init: function () {
        $( 'iframe' ).attr( 'src', function ( i, url ) { 
            return url + '?wmode=transparent';
        });
    }
};

Upvotes: 0

Matthew Lehner
Matthew Lehner

Reputation: 4027

Well, you're missing some curly braces... Try running your code through a javascript validator like jshint or jslint to help you catch these things.

Most reasonable text editors will have a plugin that can point out any validation errors on save, so that you don't have to do weird troubleshooting in the browser.. or here! ;)

Here's the valid code:

SW.wmode = {
  init: function () {
    $('iframe').each( function() {
      var url = $(this).attr('src');
      $(this).attr('src', url+"?wmode=transparent");
    });
  }
}

Upvotes: 0

65Fbef05
65Fbef05

Reputation: 4522

You're missing semicolons after each line's expression, and some braces.

SW.wmode = {
    init: function() {
        $('iframe').each(function() {
            var url = $(this).attr("src");
            $(this).attr("src",url+"?wmode=transparent");
        });
    }
};

Upvotes: 3

broesch
broesch

Reputation: 2460

try this:

SW.wmode = {
  init: function() {
  $('iframe').each(function() { //you were missing the brackets
      var url = $(this).attr("src")
      $(this).attr("src",url+"?wmode=transparent")
      });
  }
} 

Upvotes: 1

Dan Davies Brackett
Dan Davies Brackett

Reputation: 10071

You are missing the opening and closing braces of the function argument to each. Your code should be:

SW.wmode = {
    init: function() {
    $('iframe').each(function(){
        var url = $(this).attr("src")
        $(this).attr("src",url+"?wmode=transparent")
        });
    }
}

Upvotes: 1

Related Questions