How to replace href attribute in a tag NOT and tag.
So replace https://www.google.com/favicon.ico with https://www.bing.com/favicon.ico by search for the string in the href.
<link href="https://www.google.com/favicon.ico"> in html with jquery or javascript?
This should work with an tag but does NOT seem to work with the tag.
$("link[href='https://www.google.com/favicon.ico']").attr('href', 'https://www.bing.com/favicon.ico')
I'm trying to replace the favicon source in the header with the js-console.
You can try this:
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("#link").attr("href", "https://www.google.com/jquery/");
});
});
</script>
</head>
<body>
<p><a href="https://www.google.com" id="link">Google.com</a></p>
<button>Change href Value</button>
</body>
</html>
You can try this. It should be work.
<a id="link" alt="Link" href="https://www.google.com/favicon.ico">Google</a>
<script>
document.getElementById("link").setAttribute("href", "https://www.bing.com/favicon.ico");
</script>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.