alireza
alireza

Reputation: 113

What is the trouble with usage of single and double quotation

I used the below code to produce input in run time . Alert shows correctly but append causes mistake and meanwhile the single and double quotation will be changed.

   Var name1=$(a).attr ('name');
   Var idimg=name1+"z";
   Var nedi="<input type='file' name='zozo' onchange ='readURL(this , '" + idimg + "');' />";
$(nedi).appendTo ("#divv");

In run time its like :

<input type ="file" name ="zozo" onchange="readURL (this , "3z' ) ; '>

Upvotes: 0

Views: 55

Answers (1)

Krasimir
Krasimir

Reputation: 13529

Your code should look like that:

var name1 = $(a).attr('name');
var idimg = name1 + "z";
var nedi = "<input type='file' name='zozo' onchange ='readURL(this , \"" + idimg + "\");' />";
$(nedi).appendTo("#divv");

I.e. you should escape and use double quotes in onchange attribute.

Upvotes: 1

Related Questions