?
Solved

Change complete href in link

Posted on 2011-03-18
3
Medium Priority
?
456 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 2000 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 83

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…
Suggested Courses

807 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