Solved

Issue on Javascript Onclick function

Posted on 2014-03-25
7
370 Views
Last Modified: 2014-03-25
I am having an issue inserting links into an image gallery - I want the large image to be clickable.  If I use anchor links the gallery breaks so I was trying to use an onClick but for whatever reason the alert I pop up on the click always has the last image reference in it.

Not sure what I am doing wrong.

You can see it here:  http://goo.gl/4attfM
0
Comment
Question by:iceman19330
  • 3
  • 3
7 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 39954157
Because the last image is actually on top, you are just setting the opacity to 0
jQuery solution is

image=jQuery('.image-holder img').filter(function() {
  return jQuery(this).css('opacity') == '1';
});
alert(img.prop("id"))

Open in new window

0
 
LVL 8

Expert Comment

by:soupBoy
ID: 39954162
Can you post your sendImg function?
0
 

Author Comment

by:iceman19330
ID: 39954182
soupBoy --
function sendimg(a){
 alert(a.id);
 //window.location.href='b.html#id='+a.id+'&src='+a.src;
}

Open in new window


Gary -- where would I put that snippet?

thx
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 58

Expert Comment

by:Gary
ID: 39954191
I would pop it in here and remove the sendimg(this) - don't see the point of passing the object to another function
function onclick(event) {
//sendimg(this);
} 

Open in new window

0
 

Author Comment

by:iceman19330
ID: 39954217
I'm probably being obtuse Gary but I dont see that code.

I have
function sendimg(a){
 alert(a.id);
 //window.location.href='b.html#id='+a.id+'&src='+a.src;
}

Open in new window

and images with onClick="sendimg()"

Sorry if I am being difficult.
0
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 39954231
It's probably added dynamically, just add it to

function sendimg(a){
	image=jQuery('.image-holder img').filter(function() {
		return jQuery(this).css('opacity') == '1';
	});
	alert(image.prop("id")) 
	// alert(a.id);
	//window.location.href='b.html#id='+a.id+'&src='+a.src;
} 

Open in new window

0
 

Author Comment

by:iceman19330
ID: 39954261
Saaaaweet! that works
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
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…

920 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

14 Experts available now in Live!

Get 1:1 Help Now