[SalesForce] jQuery Keyup function not working

I am using jQuery Keyup function but its not working for me

<script type="text/javascript"> 
        $(document).ready(function() {
            jQuery.noConflict();
          $("firstName").keyup(function(){
             alert("first Name");
         });   

</script>

<apex:form id="PrimaryTab"> 
<div>
 <label for="inputdefault">First Name</label>
 <apex:inputField value="{!le.firstName}" styleClass="form-control id="firstName" required="true"/>
</div>
</apex:form>

Best Answer

You're using JQuery before declaring jQuery.noConflict();

Also, this statement replace the $ variable by jQuery.

And finally, as Rahul just said in his answer, Salesforce add a prefix to the ids declared on your VF page.

So you should use:

<script type="text/javascript"> 
        jQuery.noConflict();
        jQuery(document).ready(function() {
          jQuery("input[id$='firstName']").keyup(function(){
             alert("first Name");
         });   
        });

</script>
Related Topic