Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

click a button - jquery

Posted on 2010-08-13
4
Medium Priority
?
268 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
[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
  • 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 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
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…

610 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