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
Solved

Jquery select image and change link

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Html fieldset fix its height and width 4 30
multiple selects 23 48
return false must be hit after calling certain command 10 32
jQuery force form POST 7 45
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

856 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