+ Start a Discussion
RishavRishav 

how to use jQuery

// i am trying to use the jquery in visualforce but it's not working .
i tried both method by using the static resource and by using the CDN file also but no one is working
can anyone tell where i am doing the mistake?


<apex:page >
<apex:includeScript value="{!URLFOR($Resource.jqueryui,'jqueryui/js/jquery-1.10.2.js')}"/>
<apex:includeScript value="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"/>
<head>
<script>
J$ = jQuery.noConflict();
J$(document).ready(function(){
alert("hello jQuery");
)};
</script>
</head>
<apex:pageBlock >
hello
</apex:pageBlock>
</apex:page>

// i am trying to use the jquery in visualforce but it's not working . 
i tried both method by using the static resource and by using the CDN file also but no one is working 
can anyone tell where i am doing the emistake?
Best Answer chosen by Rishav
Vamsi KrishnaVamsi Krishna
Rishav,
there is a small syntax error in closing braces of the document ready function... try the below and it should work now..


<apex:page >
<apex:includeScript value="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"/>
<head>
<script>
J$ = jQuery.noConflict();
J$(document).ready(function(){
alert("hello jQuery");
});
</script>
</head>
<apex:pageBlock >
hello
</apex:pageBlock>
</apex:page>

All Answers

Vamsi KrishnaVamsi Krishna
Rishav,
there is a small syntax error in closing braces of the document ready function... try the below and it should work now..


<apex:page >
<apex:includeScript value="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"/>
<head>
<script>
J$ = jQuery.noConflict();
J$(document).ready(function(){
alert("hello jQuery");
});
</script>
</head>
<apex:pageBlock >
hello
</apex:pageBlock>
</apex:page>

This was selected as the best answer
RishavRishav
Hiii Vamshi,
                      Thanks for your help. 
                      suggest me where should i write the javascript program so that it can catch my syntax errors.
                    It becomes very hard to catch the javascript error in visualforce editor.

Thanks 
Rishav