Solved

Change complete href in link

Posted on 2011-03-18
3
421 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
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
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 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…

708 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

20 Experts available now in Live!

Get 1:1 Help Now