Solved

click a button - jquery

Posted on 2010-08-13
4
262 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

770 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