Solved

Jquery select image and change link

Posted on 2011-02-28
1
479 Views
Last Modified: 2012-05-11
I need to target a images based on the image style and change its link. Thia does not work


jQuery('#projects li img [style*=opacity: 1]').attr('href', 'some link')
0
Comment
Question by:gvilla23
1 Comment
 
LVL 82

Accepted Solution

by:
leakim971 earned 250 total points
Comment Utility
Use : jQuery('#projects li img[style*="opacity:1"]').parent("a").attr('href', 'http://www.experts-exchange.com/Programming/Languages/Scripting/AJAX/Q_26853726.html');

Test page :


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language="javascript" src="http://code.jquery.com/jquery-1.5.min.js"></script>
<script language="javascript">
	jQuery(document).ready(function() {
		jQuery('#projects li img[style*="opacity:1"]').parent("a").attr('href', 'http://www.experts-exchange.com/Programming/Languages/Scripting/AJAX/Q_26853726.html')
	});
</script>
</head>
<body>
<form id="projects">
<ul><li><a href="#"><img style="opacity:1" src="http://www.balisier148.com/photos/tortue_guadeloupe.jpg" width="160" /></a></li></ul>
</form>
</body>
</html>

Open in new window

0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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 …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

772 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

10 Experts available now in Live!

Get 1:1 Help Now