Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

loop over links to create dialog boxes on divs using .each

Posted on 2011-09-23
6
Medium Priority
?
318 Views
Last Modified: 2012-06-27
I have a table of dynamic rows with links built in - that are named based on the id of the current record.  (see code)

Then I have a set of hidden divs that are created in the same manner and named based on the id of each record as well.

What I am trying to accomplish is this

loop through every link where class = clickshow
Pull the rel attrib that defines the unique id
create a $('#div[clickshow.relAttrib.val]').dialog()

I hope this makes sense.
thanks for the help.

I have a basic understanding of the .each function but not enough to put it together w/o hours of messing up.  I don't mind an hour of messing up - but at this point all I am learning is how to get frustrated :)

thanks and God Bless!

<cfoutput query="qryClients">
<tr><td>
<a name="show#rel_ClientID#" id="show#rel_ClientID#" rel="#rel_ClientID#" class="clickshow">click me</a>
</td></tr>
</cfquery>


<cfoutput query="qryClients">
  <div id="client#rel_ClientID#" style="display:none">
    dialog contents go here
  </div>
</cfquery>

Open in new window

0
Comment
Question by:jtheriau
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 3

Accepted Solution

by:
FrankoH earned 1000 total points
ID: 36592256
Hi,

Im not 100% sure on your set up here, but if I understand correctly, then you would do something along these lines.

$(function(){
		
		//Long version
		$(".clickshow").live("click", function(e){
			// Stop anchor click from reloading the page
			e.preventDefault();
			// Pull client id from the anchor rel attribute
			var $clientid = $(this).attr("rel");
			// Concatenate to create related dialog id
			var $dialogid = "#client"+$clientid;
			// Create dialog
			$($dialogid).dialog();
		});
		
		
		// Shorter version
		$(".clickshow").live("click", function(e){
			e.preventDefault();
			$("#client"+$(this).attr("rel")).dialog();
		});
		
	});

Open in new window


I put 2 versions in just so you can see the logic a bit better & a shorter version keeping code tidier.

You dont need to use each to attach an event trigger to each matching element, jquery will do the donkey work for you.

Let me know if thats what you need.

0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 36593557
you may want to use .prop or .data rather than attr
0
 
LVL 82

Expert Comment

by:leakim971
ID: 36593665
0
How to Create Failover DNS Record Sets in Route 53

Route 53 has the ability to easily configure DNS record sets specifically for failover scenarios. These failover record sets can be configured to failover to full-blown deployments in other regions or to a static HTML page that informs your customers of the issue.

 

Author Closing Comment

by:jtheriau
ID: 36599241
Thank you !!! That was exactly what I needed.  The long dscription certainly helped me 'get it'  thanks so much!!!!
0
 

Author Comment

by:jtheriau
ID: 36599254
Mplungian - I am not sure why I would use one over the other - I just picked the rel attribute b/c I had seen it used elsewhere in the same manner

Thanks

Leakim - Thank you for the link.  It was not the solution I was looking for here - but certainly I can find use for it in another project :)  Thank you

Thank you all for the help and God Bless!
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 36600771
Right. Rel IS an attribute so no need for prop

0

Featured Post

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

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

PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…
Suggested Courses

670 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