Solved

Issue on Javascript Onclick function

Posted on 2014-03-25
7
367 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…

743 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

11 Experts available now in Live!

Get 1:1 Help Now