[SalesForce] Error in $A.getCallback() [ReferenceError: $ is not defined]

This is my controller code :

 doInit : function(component, event, helper) {
    var action = component.get("c.getpickval");
    var inputsel = component.find("InputSelectDynamic");

    var opts=[];
    action.setCallback(this, function(a) {
        for(var i=0;i< a.getReturnValue().length;i++){
            opts.push({"class": "optionClass", label: a.getReturnValue()[i], value: a.getReturnValue()[i]});
        }
        inputsel.set("v.options", opts);
        console.log($("#optionValue")[0]);
         $("#optionValue").hide();   
         $(".number").show();

    });

     //document.getElementById("optionValue").style.visibility = "hidden";

    $A.enqueueAction(action);       

},   

Here I want to hide optionValue div and show div with class named as number on my init handler. Now above error is resolved but still these hide and show functions of jquery are not working. I am using jquery 2.2.4

Best Answer

In addition Mohith's comment you may have a conflict with using the $ variable in Salesforce Lightning. You may want to use jQuery's noConflict function to remap the $ variable to something like $j. I know that noConflict re-mapping is usually needed on VisualForce pages which incorporate jQuery.

Related Topic