Nalla Srinivas
Nalla Srinivas

Reputation: 933

How to add onclick to anchor tag in java script

I am preparing anchor tag adding to div in jquery but onclick function is not calling so can any one help me to solve this. my code is like this.

function prepareItemsDiv(url,type){
$("#itemsRootDiv").html('');
$.ajax({
    url: url,
    type: "GET",
    async:false,
    success:function(response){
        $.each(response, function(index,data){
            console.log(data);

                var div= "<div class='col-md-3 col-sm-4 col-xs-6    myBox'     >"+
                            "<div class='dummy'></div>"+
                            "<a href='javascript:void(0);' class='thumbnail purple' onlclick='return callUnits("+data.id+","+data.bPrice+","+data.rPrice+","+type +");'>"
                            +data.itemName+"</a>'</div>";

                $("#itemsRootDiv").append(div);

        });         
    },
    error:function(error){
        alert("some problem occured please contact admin");
        return false;
    }

}); 

}

callUnits() is not calling onclick of anchor tag. how can i call this function.

Upvotes: 0

Views: 349

Answers (1)

Walter Misar
Walter Misar

Reputation: 74

Seems to be a typo: "onlclick" instead of "onclick". There's a stray single quote after the anchor closing too.

Upvotes: 2

Related Questions