views:

80

answers:

7

So I'm working on a little bit of jQuery for a site I'm working on and for some reason when I put single quotes inside double quotes Firefox, in it's eternal glory, changes them to double quotes thus breaking my code.

I even tried putting it in an external javascript file even though I'm just prototyping at this point. No good. Wouldn't load the file!

$("#clips").after("<ul id='slideshow-nav'><li><a id='gallery-next' href='#' title='View the next piece'>Next</a></li><li><a id='gallery-prev' href='#' title='View the previous piece'>Prev</a></li></ul>");

Am I doing something wrong?

+1  A: 

Have you tried switching the single and double quotes?

$("#clips").after('<ul id="slideshow-nav"><li><a id="gallery-next" href="#" title="View the next piece">Next</a></li><li><a id="gallery-prev" href="#" title="View the previous piece">Prev</a></li></ul>');
jimyi
+1  A: 

Have you considered:-

$("#clips").after('<ul id="slideshow-nav"><li><a id="gallery-next" href="#" title="View the next piece">Next</a></li><li><a id="gallery-prev" href="#" title="View the previous piece">Prev</a></li></ul>')

?

Whilst its quite normal to have ' and " usage interchangable in Javascript usage of ' to delimit attribute values in HTML / XML is rare.

AnthonyWJones
+1  A: 

I can't reproduce the error in FF3.5.

<div id="clips">test</div>
<script type="text/javascript">
  $("#clips").after("<ul id='slideshow-nav'><li><a id='gallery-next' href='#' title='View the next piece'>Next</a></li><li><a id='gallery-prev' href='#' title='View the previous piece'>Prev</a></li></ul>");
</script>

gives me:

<div id="clips">test</div>
<ul id="slideshow-nav">
  <li><a title="View the next piece" href="#" id="gallery-next">Next</a></li>
  <li><a title="View the previous piece" href="#" id="gallery-prev">Prev</a></li>
</ul>
Joe
+1  A: 

Works fine for me in FF 3.5.2. Are you wrapping it in $(function() { }); to make sure that the DOM is loaded?

<html>
<head>
<title>tt</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js"&gt;&lt;/script&gt;
<script type="text/javascript">
    $(function() {
         $("#clips").after("<ul id='slideshow-nav'><li><a id='gallery-next' href='#' title='View the next piece'>Next</a></li><li><a id='gallery-prev' href='#' title='View the previous piece'>Prev</a></li></ul>");
    });
</script>
</head>

<body>
<div id='clips'></div>
</body>
</html>
tvanfosson
A: 

Looks good. A few things to try:

Restructure for readability (is same code, using an array with a .join('') on the end):

$("#clips")
.after( [
   "<ul id='slideshow-nav'>",
       "<li><a id='gallery-next' href='#' title='Next piece'>Next</a></li>",
       "<li><a id='gallery-prev' href='#' title='Previous piece'>Prev</a></li>",
   "</ul>"
].join('')
);

Rename ids just to make sure there are no conflicts on the page (often has odd errors):

$("#clips")
.after( [
   "<ul id='slideshow-nav2'>",
       "<li><a id='gallery-next2' href='#' title='Next piece'>Next</a></li>",
       "<li><a id='gallery-prev2' href='#' title='Previous piece'>Prev</a></li>",
   "</ul>"
].join('')
);

Use all double quotes with escape characters:

$("#clips")
.after( [
   "<ul id=\"slideshow-nav2\">",
       "<li><a id=\"gallery-next2\" href=\"#\" title=\"Next piece\">Next</a></li>",
       "<li><a id=\"gallery-prev2\" href=\"#\" title=\"Previous piece\">Prev</a></li>",
   "</ul>"
].join('')
);
Matt Gardner
A: 

Hmm this is working for me?

http://pastebay.com/51896

GaVrA
A: 

Both single and double quotes are valid in JavaScript and HTML:

HTML: "Double style quotes are the most common, but single style quotes are also allowed."

JavaScript: "A string literal is zero or more characters enclosed in single or double quotes."

Kobi