Solved

passing parameters to jquery

Posted on 2012-03-27
2
376 Views
Last Modified: 2012-03-28
I am trying to use the jquery toggle function to show/hide multiple div blocks that are generated dynamically using a coldfusion loop. Each div block would have a separate and unique id that is automatically generated. I want to be able to use one toggle function to toggle each  div block separately but do not know how to pass div id names to the function to show/hide a specific block. (if there is a better way to do this, please let me know also)

For the id in the attached code I just picked seeall10 and whatever10 as one of the dynamically generated div tags but I would need to replace that with some sort of passed parameter or variable so that all div tags would work.

Thank you!
code.txt
0
Comment
Question by:cbeverly
2 Comments
 
LVL 7

Accepted Solution

by:
Lalit Chandra earned 500 total points
ID: 37773061
you can try the following in jquery

$(function() {
$("p[id^='seeall']").click(function() {
   $(this).next("div").toggle();
});
});

This will solve your issue as this will bind your all  P tags with the id starting seeall.

Hope your problem has been fixed by the above code sample.
0
 

Author Closing Comment

by:cbeverly
ID: 37778265
This worked perfectly!!!
Thank you so much.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question