Solved

Issue on Javascript Onclick function

Posted on 2014-03-25
7
377 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
[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
  • 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
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

 
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

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…
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 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…

739 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