function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Ritesh__Ritesh__ 

Jquery is not working as expected in visualforce

i am writing a visualforce in which i am using dynamic components my visualforce code is

<apex:pagetitle="Salesforce SOQL Offset Example Using Visualforce"standardStylesheets="false"controller="dynamic_visualforce_with_soql_offset"sidebar="false"readOnly="true"cache="false"showHeader="false"><scriptsrc="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script><scriptsrc="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.1/jquery-ui.min.js"></script><scripttype="text/javascript">$(function(){$("[id$=prev]").click(function(){alert('Hello World');});});</script><apex:sectionHeadersubtitle="SOQL Offset Example w/Dynamic Page Buttons"title="Square Root Table"/><apex:form><apex:pageBlock><apex:actionFunctionaction="{!refreshGrid}"name="queryByPage"reRender="myPanel,myButtons"><apex:paramname="firstParam"assignTo="{!selectedPage}"value=""/></apex:actionFunction><apex:dynamicComponentcomponentValue="{!myCommandButtons}"/><apex:pageBlockSectiontitle="Numbers and their Square Roots (Total List Size: {!total_size})"collapsible="false"><apex:outputPanelid="myPanel"><apex:pageMessagesid="theMessages"/><apex:pageBlockTablevalue="{!numbers}"var="n"align="center"><apex:columnvalue="{!n.Id}"/><apex:columnvalue="{!n.Name}"/><apex:facetname="footer">Showing Page # {!pageNumber} of {!totalPages}</apex:facet></apex:pageBlockTable></apex:outputPanel></apex:pageBlockSection></apex:pageBlock></apex:form></apex:page>

and segment for generating dynamic component is

 
Ritesh__Ritesh__

the segment for generating dynamic ocmponent is 

publicComponent.Apex.pageBlockButtons getMyCommandButtons(){//the reRender attribute is a set NOT a stringSet<string> theSet =newSet<string>();        theSet.add('myPanel');        theSet.add('myButtons');        integer totalPages;if(math.mod(total_size, list_size)>0){            totalPages = total_size/list_size +1;}else{            totalPages =(total_size/list_size);}        integer currentPage;if(selectedPage =='0'){            currentPage = counter/list_size +1;}else{            currentPage = integer.valueOf(selectedPage);}Component.Apex.pageBlockButtons pbButtons =newComponent.Apex.pageBlockButtons();        
        pbButtons.location ='top';        pbButtons.id ='myPBButtons';Component.Apex.outputPanel opPanel =newComponent.Apex.outputPanel();        opPanel.id ='myButtons';//the Previous button will alway be displayedComponent.Apex.commandButton b1 =newComponent.Apex.commandButton();      b1.id ='prev';        b1.expressions.action ='{!Previous}';        b1.title ='Previous';        b1.value ='Previous';        b1.expressions.disabled ='{!disablePrevious}';        
        b1.reRender = theSet;        opPanel.childComponents.add(b1);for(integer i=0;i<totalPages;i++){Component.Apex.commandButton btn =newComponent.Apex.commandButton();if(i+1==1){                btn.title ='First Page';                btn.value ='First Page';                btn.rendered =true;}elseif(i+1==totalPages){                btn.title ='Last Page';                btn.value ='Last Page';                btn.rendered =true;}else{                btn.title ='Page '+string.valueOf(i+1)+' ';                btn.value =' '+string.valueOf(i+1)+' ';                btn.rendered =false;}if((i+1<=5&& currentPage <5)||(i+1>= totalPages-4&& currentPage > totalPages-4)||(i+1>= currentPage-2&& i+1<= currentPage+2)){                btn.rendered =true;}if(i+1==currentPage){                btn.disabled =true; 
                btn.style ='color:blue;';}  

            btn.onclick ='queryByPage(\''+string.valueOf(i+1)+'\');return false;';            opPanel.childComponents.add(btn);if(i+1==1|| i+1== totalPages-1){//put text after page 1 and before last pageComponent.Apex.outputText text =newComponent.Apex.outputText();                text.value ='...';        
                opPanel.childComponents.add(text);}}//the Next button will alway be displayedComponent.Apex.commandButton b2 =newComponent.Apex.commandButton();        b2.expressions.action ='{!Next}';        b2.title ='Next';        b2.value ='Next';        b2.expressions.disabled ='{!disableNext}';        
        b2.reRender = theSet;        opPanel.childComponents.add(b2);//add all buttons as children of the outputPanel                        pbButtons.childComponents.add(opPanel);return pbButtons;}

but when i try to click on previous button it is not showing an alert