How to insert HTML content into div with jQuery without using \ "(backslash and double quotation marks)

2

I use a CMS called uCoz and it has a <?$RELATED_ENTRIES$(5)?> variable that displays postings related to the page my visitor is reading. I would like to put the related links between the post text, but it does not work for CMS system rule, which does not have root scripts open.

The solution I found was to create a <div class="related"></div> and insert the content that the <?$RELATED_ENTRIES$(5)?> variable generates using jQuery. But in Javascript the double quotation marks have to put \ (backslash) before and the generated code does not have this \ (backslash)

The code that the variable generates is thus

<ul class="uRelatedEntries">
<li class="uRelatedEntry"><a href="/link#1">Lorem Ipsum</a></li>
<li class="uRelatedEntry"><a href="/link#2">Lorem Ipsum</a></li>
<li class="uRelatedEntry"><a href="/link#3">Lorem Ipsum</a></li>
</ul>

Only HTML is compact on a single line.

    
asked by anonymous 08.02.2014 / 15:34

1 answer

4

In this case, enclose the variable in single quotation marks:

$('div.related').html('<?$RELATED_ENTRIES$(5)?>');

You would only have to put \ (backslash) before the double quotation marks if the variable was enclosed in double quotation marks: "<?$RELATED_ENTRIES$(5)?>" (this way it does not work because you would need the backslash).

However, even if it involves the variable with single quotes as suggested, if single quotation marks appear in the contents of the variable, then you would need the backslash before them.

In short:

  • If the contents of the variable have double quotation marks, enclose it with single quotation marks.
  • If the contents of the variable have single quotation marks, enclose it with double quotation marks.
  • If the contents of the variable have both single and double quotes, you will not be able to use the text without being able to change it (which is not possible with the uCoz system).
08.02.2014 / 16:04