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 ?

3
  • 1
    don't do this? Make the base element, then add the attributes with the att() chaining function: $('<button>').attr({ class: "btn" value: "...", title: "..."}).insertAfter... etc. Also if you need a button, use a button. input type=button doesn't add anything to a form; its value can't contribute to the form post, it's just "a button", so be semantic about that. Commented Apr 15, 2016 at 4:03
  • Have you tried this? - $("<input class='btn' type='button' value='[[[send]]]' title='' />").insertAfter("#something"); Commented Apr 15, 2016 at 4:03
  • @Developer107: If I do this, I will be getting same error in value field if the translated string contains single quotes. Commented Apr 15, 2016 at 4:12

2 Answers 2

3

Try the following:

$('<input>', { class:"btn",type:"button",value:"[[[send]]]",title:""})
Sign up to request clarification or add additional context in comments.

2 Comments

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 and madalin : 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+
0

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

$('<input/>', {class:"btn", type:"button", title:""}).val( "[[[send]]]" )
.insertAfter('#something');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.