HTML/Javascript

This code snippet shows how to perform different actions when Javascript is enabled or disabled. In this example, if Javascript is enabled, the add to cart button will show a pop-up message notifying the user that the item has been added. If, however, JS is disabled, it takes the user to “cart.html”.

<!doctype html>
<html>
<head>
	<title>demo</title>
</head>
<body>
	<a href="" id="add-to-cart" onclick="fun()"></a>
	<script>
		document.getElementById("add-to-cart").innerHTML="Add to Cart";
		function fun() {
			alert("Item Added!");
		}
	</script>
			                      
	<noscript>
		<a href="cart.html">Add to Cart</a>
	</noscript>
</body>
</html>
Advertisements