Solved

Jquery select image and change link

Posted on 2011-02-28
1
484 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
[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
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

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

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

Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…

688 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