Solved

Jquery select image and change link

Posted on 2011-02-28
1
481 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
ID: 35001942
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
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 create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

816 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

9 Experts available now in Live!

Get 1:1 Help Now