Satch3000
Satch3000

Reputation: 49384

Onclick does not fire ... possible javascript syntax issue

I am trying to get an onclick to fire but it just won't, been trying for hours now.

Can anyone see any issues with the following code?

output += '<li><a href="#" onclick="window.plugins.childBrowser.showWebPage('http://www.google.com',{ showLocationBar: true });">link</a></li>';

I have the feeling it's something to do with the syntax somewhere.

Upvotes: 0

Views: 71

Answers (3)

Pete
Pete

Reputation: 2558

You have a '-delimited string within a '-delimited string. You need to escape the inner ':

output += '<li><a href="#" onclick="window.plugins.childBrowser.showWebPage(\'http://www.google.com\',{ showLocationBar: true });">link</a></li>';

Upvotes: 2

Niet the Dark Absol
Niet the Dark Absol

Reputation: 324620

Look at the colour coding of your own post. Clearly you need to escape the single quotes inside the string.

output += '<li><a href="#" onclick="window.plugins.childBrowser.showWebPage(\'http://www.google.com\',{ showLocationBar: true });">link</a></li>';

Upvotes: 3

epascarello
epascarello

Reputation: 207501

You have a problem with quotes. Look at the error console I am sure it is yelling at you.

You need to escape the with a \

output += '<li><a href="#" onclick="window.plugins.childBrowser.showWebPage(\'http://www.google.com\',{ showLocationBar: true });">link</a></li>';

Upvotes: 3

Related Questions