Solved

click a button - jquery

Posted on 2010-08-13
4
261 Views
Last Modified: 2012-05-10
in my page have a jquery lightbox, colorbox.

So it plays a slideshow and we can group pictures using "rel". So i have group of images and images have links to high res images, these images have the same "rel" and when click on an image slideshow starts.

But the problem is slideshow only starts if user click on a small image which has the <a rel="group">

I want to start the slideshow from a separate button. so what I did is I set something like this.

$("a[rel='albumSlideshow']").colorbox(
										{
											transition:"fade", 
											slideshow:true, 
											slideshowAuto: true,
											maxWidth: '80%',
											initialWidth: '80%',
											scalePhotos: true
											
										})
								$(".albumSlideshow").click(function(){
									$("a[rel='albumSlideshow]").click();
								})

Open in new window


So I've configured the lightbox with a slideshow and the button is "albumSlideshow" so when user click that button a[rel='albumSlideshow]' also get clicked, the problem is page has lots of a[rel='albumSlideshow] so it screws up the slideshow.

What I wants to do is, click only one a[rel='albumSlideshow]. Well I can assign an ID to one of this links and set it to be clicked, but this is a dynamic site.

Hope it make sence

<a rel="group" href="real_img.jpg">Small image here</a>
0
Comment
Question by:sahanz
  • 2
4 Comments
 
LVL 7

Expert Comment

by:jhp333
ID: 33433629
You need to find a relationship between the button and the <a>.
For example, if the button and <a> are siblings, i.e. have a common direct parent, you can do:

$(".albumSlideshow").click(function(){
  $(this).siblings("a[rel='albumSlideshow]").click();
});

Or if they have a common ancestor div, you can do:

$(".albumSlideshow").click(function(){
  $(this).parents('div:first').find("a[rel='albumSlideshow]").click();
});
0
 
LVL 7

Accepted Solution

by:
jhp333 earned 500 total points
ID: 33433653
Or if the <a> is one of the follow siblings of the button:

$(".albumSlideshow").click(function(){
  $(this).nextAll("a[rel='albumSlideshow]:first").click();
});
0
 
LVL 5

Expert Comment

by:KiasChaos83
ID: 33438238
Using jQuery it's fairly easy. You would use the trigger() method. E.g.

$("a[rel='albumSlideshow]").trigger("click");

And that will trigger the javascript in the Click event.
0
 
LVL 1

Author Closing Comment

by:sahanz
ID: 33555483
Thanks a lot,
Tried this

$(".albumSlideshow").click(function(){
  $("a[rel='albumSlideshow']:first").click();
});
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
JS Plugin 4 29
Tableau and Javascript: How to export an array to excel with formatting 11 58
Google Sheets Script 21 53
insert text field data into html script 13 21
Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
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…

919 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now