Jack Clarke Jack Clarke - 6 months ago 12
jQuery Question

jQuery Syntax Error for custom wordpress script

Can anyone see why I'm getting a syntax error on line 19 of this piece of code? To give some context: it's a small javascript to get an image to appear in a random place, at a relatively random size, at a random orientation on a wordpress page. I'm getting an error on the

});
just after the
background url...
The main code appears within the
//* Required *//
notes. Thanks in advance

( function( $ ) {
var body = $( 'body' ),
_window = $( window ),
nav, button, menu;

nav = $( '#site-navigation' );
button = nav.find( '.menu-toggle' );
menu = nav.find( '.nav-menu' );

//* Required *//

(function makeDiv(){
// vary size for fun
var divsize = ((Math.random()*100) + 50).toFixed();
$newdiv = $('<div/>').css({
'width':divsize+'px',
'height':divsize+'px',
'background-url’:’/wp-content/themes/idealpress/images/popup.svg'
});

// make position sensitive to size and document's width
var posx = (Math.random() * ($(document).width() - divsize)).toFixed();
var posy = (Math.random() * ($(document).height() - divsize)).toFixed();
var rNum = (Math.random() * 360 ) + 1;

$newdiv.css({
'position':'absolute',
'left':posx+'px',
'top':posy+'px',
'display':'none',
'-webkit-transform': 'rotate('+rNum+'deg)',
'-moz-transform': 'rotate('+rNum+'deg)'
}).appendTo( 'body' ).fadeIn(100, function(){
makeDiv();
});
})();
//* Required *//


} )( jQuery );

Answer

You are using the wrong quotes.

Change this line:

'background-url’:’/wp-content/themes/idealpress/images/popup.svg'

into this:

'background-url':'/wp-content/themes/idealpress/images/popup.svg'
               ^ ^

Hence the JSON syntax is invalid.