Using Jquery functions on a ClientLibrary | Community
Skip to main content
Level 2
March 1, 2016
Solved

Using Jquery functions on a ClientLibrary

  • March 1, 2016
  • 7 replies
  • 4324 views

I am having some trouble on using a Jquery function my js file inside my clientLib folder. Inside my js file the code that I used was:

$(document).ready(function(){ alert("test") $('.storeLocatorFormSubmit').click(function(){ alert("Hello world"); }); });

and then stumbled on a question on Stackoverflow where it suggest that instead of using the "$" I replaced it the word "jQuery" so after changing the code into this:

jQuery(document).ready(function(){ alert("test") jQuery('.storeLocatorFormSubmit').click(function(){ alert("Hello world"); }); });

The alert with value of "test" is now being displayed on the page but the alert box does not show every time I click the button of "storeLocatorFormSubmit".

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by haroldm43863165

Thank you for your responses.

For the

jQuery('.storeLocatorFormSubmit')

I am trying to bind a click function to a button once the form is being submitted. I gave another shot to use the keyword "jQuery" rather than "$" and it now works as expected.

7 replies

smacdonald2008
Level 10
March 1, 2016

We have a JQUERY article with AEM https://helpx.adobe.com/experience-manager/using/integrating-jquery-framework-cq.html.

The $ is valid syntax. Try using Chrome and place a break point on the JS method. Your code looks fine. 

edubey
Level 10
March 1, 2016

As Scott mentioned using $ is valid syntax and u can use it.

Check the error in browser console when you are using '$'

Make sure you use jquery code only once jquery library has been loaded.

Are you trying to get click in event on particular class?

Level 2
March 1, 2016

Thank you for the quick response, yes I tried the tutorial based on the given article. But for clarification the jquery code is located on an external file. The way I setup my Client Library Folder is that I declared a dependency on the jquery library that is already present on AEM.

Level 2
March 1, 2016

I think that the $ is valid if the Jquery code is located inside the script tag (<script>) but AEM does not recognized it if the code is on its external javascript file. Please correct me on this one.

edubey
Level 10
March 1, 2016

U can use $ irrespective of way you load jquery

Jitendra_S_Toma
Level 10
March 1, 2016

Hi,

Go to browser console where you have loaded your page with this code. Type below code in the browser console. 

jQuery('.storeLocatorFormSubmit')

Does it return "undefined" or an object?. if it is undefined, it means, Event binding is not happening.

haroldm43863165AuthorAccepted solution
Level 2
March 2, 2016

Thank you for your responses.

For the

jQuery('.storeLocatorFormSubmit')

I am trying to bind a click function to a button once the form is being submitted. I gave another shot to use the keyword "jQuery" rather than "$" and it now works as expected.