0
 $('<input class="btn" type="button" value="[[[send]]]" title="" />').insertAfter('#something');

When I include this input element from js to html, I am using single quotes('). If you see value attribute value="[[[send]]]" I have used brackets for localization. If the translated language contains single quotes(french, italian) I am getting ')'missing error in script.

EX: $('<input class="btn" type="button" value="send'vara" title="" />').insertAfter('#something');

Is there any option to include input element without using single quotes ? or Is there any other representation for single quotes in JS ?

Shesha
  • 1,857
  • 6
  • 21
  • 28
  • 1
    don't do this? Make the base element, then add the attributes with the `att()` chaining function: `$(' – Mike 'Pomax' Kamermans Apr 15 '16 at 04:03
  • Have you tried this? - `$("").insertAfter("#something");` – Developer107 Apr 15 '16 at 04:03
  • @Developer107: If I do this, I will be getting same error in value field if the translated string contains single quotes. – Shesha Apr 15 '16 at 04:12

2 Answers2

3

Try the following:

$('<input>', { class:"btn",type:"button",value:"[[[send]]]",title:""})
madalinivascu
  • 32,064
  • 4
  • 39
  • 55
  • See portion of link at _"The name "class" must be quoted in the object since it is a JavaScript reserved word, and "className" cannot be used since it refers to the DOM property, not the attribute."_ – guest271314 Apr 15 '16 at 04:51
  • 2
    @guest271314 and madalin : http://stackoverflow.com/a/9568622/3702797 "*Note that reserved words are allowed to be used as unquoted property names in **ES5**.*" so even `{var : 'xxx'}` is allowed in ES5+ – Kaiido Apr 15 '16 at 05:10
0

You can use the .val() method to set the value:

$('<input/>', {class:"btn", type:"button", title:""}).val( "[[[send]]]" )
.insertAfter('#something');
PeterKA
  • 24,158
  • 5
  • 26
  • 48