Q:

onclick method not working jquery

i am trying to append a anchor tag when user select's an option from select and its appending the anchor tag properly when user select's any option from select.
code for appending anchor tag:
$(function () {
 //others codes ......
 $('#anchor_placeholder').append(
     "<a class='btn btn-info btn-xs' 
         onClick='placeholderclick("+$(option).val()+")'>" + $(option).val() + "</a>"
 );
});
function placeholderclick(value) {
    alert(value);
}

now when i click on a appended anchor link its does not show me any alert message, but if i remove the parameters of placeholderclick("+$(option).val()+") from the append function above then its showing me alert...
i am wondering how can i alert the parameter value (parameter values comes from append method)
please suggest or help me to solve this issue, sorry for my bad english,
thanks in advance.

A:

you need to escape double quotes
    $('#anchor_placeholder').append(
        "<a class='btn btn-info btn-xs'onClick='placeholderclick(\""+$(option).val()+"\")'>" + $(option).val() + "</a>"
    );

Suppose you have selected value apple than your link generated will be like this
<a class='btn btn-info btn-xs' onClick='placeholderclick(apple)'>apple</a>

so javascript will see your value (apple) has variable which won't be present.
if you escape double quotes than your link will be like this
<a class='btn btn-info btn-xs' onClick='placeholderclick("apple")'>apple</a>

now your value (apple) will be consider as string.

