views:

92

answers:

3

I'm getting this error with this javascript can anyone help me figure out what i'm doing wrong?

$(this).prepend('<a class="booknow2 sidelink sidelinkNew" href="javascript:__doPostBack('SetSess','')"><img src="../../images1/button/leftEdge.png" width="4" height="35" style="float:left; margin:0; padding:0;" alt="book now" /><img src="../../images1/button/rightEdge.png" width="4" height="35" style="float:right; margin:0; padding:0;" alt="book now" /><span>Check availability &raquo;</span></a>');

It's giving me the error

missing ) after argument list

Can anyone help?

Thanks

Jamie

+8  A: 

It looks like you need to escape some single quotes in there:

... __doPostBack(\'SetSess\',\'\') ...
Daniel Vassallo
Thanks should of seen that really!
Jamie Taylor
+3  A: 

You need to escape enclosed quotes like this:

__doPostBack(\'SetSess\',\'\')
elusive
+1  A: 

Just for your information, but there is a better syntax then to prepend the whole thing as a huge HTML fragment. You can construct the whole thing with jQuery from scratch:

var anchor = $('<a></a>').addClass('booknow2 sidelink sidelinkNew')
.attr('href', "javascript:__doPostBack('SetSess','')")
.prependTo(this); // Try to use event handlers instead

$('<img>').attr({ // Try to use CSS instead
    'width': '4',
    'height': '35',
    'alt': 'book now',
    'src': '../../images1/button/rightEdge.png'
}).css({
    'float': 'left',
    'margin': 0,
    'padding': 0,
}).appendTo(anchor);

$('<span></span>').html('Check availability &raquo;').appendTo(anchor);
Yi Jiang
That's the jQuery way. +1 The `attr('href', …)` can be replaced by `click(function() {…})` to make it even more idiomatic.
Tomalak