1

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

1
  • 2
    Look at the code highlighting applied here. See the error? ;)
    – Yi Jiang
    Sep 9, 2010 at 12:20

3 Answers 3

9

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

... __doPostBack(\'SetSess\',\'\') ...
1
  • 1
    Thanks should of seen that really! Sep 9, 2010 at 12:24
3

You need to escape enclosed quotes like this:

__doPostBack(\'SetSess\',\'\')
3

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>', {
    'class': 'booknow2 sidelink sidelinkNew', 
    // Try to use event handlers instead - inline event handlers are *bad*
    href: "javascript:__doPostBack('SetSess','')"
}).prependTo(this); 

$('<img>', {
    'width': '4',
    'height': '35',
    'alt': 'book now',
    'src': '../../images1/button/rightEdge.png'
}).css({
    // Try to use CSS instead - add a class 
    // and define the CSS in a separate stylesheet
    'float': 'left',
    'margin': 0,
    'padding': 0,
}).appendTo(anchor);

$('<span>', {
    html: 'Check availability &raquo;'
}).appendTo(anchor);
1
  • That's the jQuery way. +1 The attr('href', …) can be replaced by click(function() {…}) to make it even more idiomatic.
    – Tomalak
    Sep 9, 2010 at 12:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.