Solved

Issue on Javascript Onclick function

Posted on 2014-03-25
7
374 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
DevOps Toolchain Recommendations

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

 
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

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…
This article discusses how to create an extensible mechanism for linked drop downs.
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…

773 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