?
Solved

Syntax issue with javascript and quotes

Posted on 2012-08-25
1
Medium Priority
?
357 Views
Last Modified: 2012-08-25
Hi all,

I am having some issues with code synta not working...

For example:

This code works fine:

<li>
<a href="#" onclick="window.plugins.childBrowser.showWebPage('http://www.mysite.com');">
<img src="images/thumb.jpg" />
<h3>Text Here</h3>
<p>text</p>
</a>
</li>

Open in new window


But this code (added via javascript does not):

output += '<li><a href="#" onclick="window.plugins.childBrowser.showWebPage('http://mysite.com');"><img src="'+value.thumbnail_url+'" /><h3>'+value.title+'</h3>'+value.body+'</a></li>';

Open in new window


I think the problem is here:

onclick="window.plugins.childBrowser.showWebPage('http://mysite.com');" ....

to be more precise here:

('http://mysite.com');

but I've tried:

("'http://mysite.com'") and (&quote;'http://mysite.com'"e;) but it still doesn't work.

Anyone got any ideas please?

Thanks
0
Comment
Question by:error77
1 Comment
 
LVL 25

Accepted Solution

by:
lwadwell earned 2000 total points
ID: 38332022
try escaping (\) the inner single quotes e.g.
output += '<li><a href="#" onclick="window.plugins.childBrowser.showWebPage(\'http://mysite.com\');"><img src="'+value.thumbnail_url+'" /><h3>'+value.title+'</h3>'+value.body+'</a></li>';

Open in new window

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question