0

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

5 Answers 5

3

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");
        });
    }
};
Sign up to request clarification or add additional context in comments.

1 Comment

+1 for additionally correcting the indentation and adding the semi-colon at the end.
1

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

1 Comment

that was it, thanks Dan waiting the obligatory 8 looong minutes to accept.
1

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

Comments

0

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

Comments

0

I refactored your code a bit:

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

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.