issue with jquery not executing a function

I have to develop a faq section, where users search for contents. When one searches for contents, it brings back some results and wanted to show and hide certain div.

http://shaperweb.com/sample/faq_json.html

When you enter a search term "man" this should bring you back with two results.

each results have the following structure.

<h5 class="plus" id="h5code">title of the faq</h5>
<div "display:none">description of faq</div>

I have written code for executing while some one clicks on h5.

      $('h5').on('click',function(e) {
            //e.preventDefault();
            //$(this).toggleClass('minus plus').next().toggle('slow', 'swing');
            //return false;
            alert ('hai');
      });

      $('#results h5 minus').next().show();
      $('#results h5 plus').next().hide();
      

Not sure why its not getting into the function.

So question is can you guys help me in 2 things.
1. Why is my function not executed?
2. How can i show and hide the following div, which will have the description of the faq?
Perumal RMAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Snarf0001Commented:
It's throwing an error on the actual handler hookup.
You're using a very old version of jquery (1.4), the .on() function wasn't introduced until 1.7.

I'd suggest just upgrading to the most recent, but if you have to use this one, then change

$('h5').on('click',function(e) {

to

$('h5').click(function(e) {
0
Tom BeckCommented:
The script block that includes the js_script.js file is outside the <body> tags.

Error from Firebug on the line with the handler:

TypeError: $(...).on is not a function
0
Perumal RMAuthor Commented:
Hi snarf & Tom,

Did the changes you guys requested. Still doesnt help. Any ideas?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Ray PaseurCommented:
Just looked at the "view source" of the link.  It looks like you have two links to the jquery file.  Why not just use one link from the CDN:
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>

Open in new window

0
Tom BeckCommented:
If you insist on using that old version of query then you can try this:

       
$('h5').live('click', function(e) { 
		//e.preventDefault();
		//$(this).toggleClass('minus plus').next().toggle('slow', 'swing');
		//return false;
		alert ('hai');
	});

Open in new window


.click does not work for dynamically created elements and .on will not work with that version of jquery.
0
Ray PaseurCommented:
Here is the simplest jQuery / AJAX "Hello World" exercise I could find.  Hopefully the article explains some of the thinking and design that you'll want to consider when you try to use jQuery.
http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Jquery/A_10712-The-Hello-World-Exercise-with-jQuery-and-PHP.html
0
GaryCommented:
Use this code for your click

$("#results h5").live("click",function(){
	$(this).next().toggle()
})

Open in new window

Don't know what the minus/plus are supposed to be referencing since they're is nothing on the page for them
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Perumal RMAuthor Commented:
It worked like a charm. Easy one and you gave the complete code. Thank you very much
0
Tom BeckCommented:
I gave you the code as well in an earlier post. The key was to use .live instead of click.
0
GaryCommented:
The question wasn't about that
0
Tom BeckCommented:
My comment resolved part 1 of a two part question.
0
GaryCommented:
Click Request Attention at the top unless the OP comes back to the Q
0
Tom BeckCommented:
I know how it works.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
jQuery

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.