Solved

Change complete href in link

Posted on 2011-03-18
3
441 Views
Last Modified: 2012-05-11
I am trying to change the complete href, in Jquey  or javascript.

I am able to change the href, but it keeps part of the site url.

I change the default from javascript;; to whatever.html, but when I change it back to its original (href javascript;;) the link looks like href www.mysite.htmljavascript;;,
 not just javascript;;




 

if  (jQuery('#projects li img[style*=opacity: 1]').attr('title') == "pro173");
jQuery("#pro173").attr({
  href: 'somepage.html',
   
 })}else{
jQuery("#pro173").attr({
  href: 'javascript;;',
   
});

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
3 Comments
 
LVL 13

Accepted Solution

by:
darren-w- earned 500 total points
ID: 35167550
I've modified the code a bit
         $(function(){
            if  ($('#projects li img[style*=opacity: 1]').attr('title') == "pro173")
            {            
               $("#pro173").attr('href', 'somepage.html')
            }else{
               $("#pro173").attr('href','javascript;;');
            }
         });

Open in new window

0
 

Author Comment

by:gvilla23
ID: 35167954
thanks, let me try it!
0
 
LVL 82

Expert Comment

by:leakim971
ID: 35168022
Check this :


<html>
<head>
<script src="http://code.jquery.com/jquery-1.5.1.min.js"></script>
<script>
	$(document).ready(function() {
		jQuery("li a", "#projects").each(function() {
			var found = $("img[style*='opacity:1']", this).length > 0;
			$(this).attr("href", found?"http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_26896707.html":"javascript:void(0)");
		})
	});
</script>
<body>
<ul id="projects">
<li><a href="javascript:void(0)"><img src="http://www.wikidive.com/Photo/Images/guadeloupe.jpg" style="opacity:1" src="" width=320 /></a></li>
<li><a href="javascript:void(0)"><img src="http://www.wikidive.com/Photo/Images/guadeloupe.jpg" style="opacity:0.30" src="" width=320 /></a></li>
<li><a href="javascript:void(0)"><img src="http://www.wikidive.com/Photo/Images/guadeloupe.jpg" style="opacity:0.30" src="" width=320 /></a></li>
</ul>
</body>
</html>

Open in new window

0

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
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…

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