gvilla23
asked on
Change complete href in link
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;;',
});
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;;',
});
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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>
ASKER