Solved

click a button - jquery

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
replacing inline javascript with jquery 4 59
jQuery element reference issue 2 32
hide and show spans from dropdown selection 3 30
Jquery syntax 12 20
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…
Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
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…

733 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