Evgeny Krasyuk Evgeny Krasyuk - 5 months ago 19
jQuery Question

jsfiddle code not working in browser

My rating system working in jsfiddle:
https://jsfiddle.net/hp2L1ntd/

I created html file, containing all components from jsfiddle. But when I'm trying it in my browser it isn't working. Thanks for help.

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style>
body {
font-family: Verdana;
}
h1, h2, h3 {
color: darkblue;
}
.rating-circle {
height: 2em;
width: 2em;
border: .1em solid black;
border-radius: 1.1em;
display: inline-block;
margin: 0;
padding: .1em;
}

.rating-hover {
background-color: yellow;
}

.rating-chosen {
background-color: green;
}
</style>
</head>
<body>
<h1>Contoso Web Developer Conference</h1>
<h2>Finding elements using jQuery</h2>
<div>This session is about identifying elements using jQuery methods and selectors.</div>
<h3>Rate this session</h3>
<div id="rating-container">
<div class="rating-circle"></div>
<div class="rating-circle"></div>
<div class="rating-circle"></div>
<div class="rating-circle"></div>
<div class="rating-circle"></div>
</div>

<script src="//ajax.aspnetcdn.com/ajax/jQuery/jquery-2.1.4.min.js"></script>

<script>
$(document).ready(function() {
$('.rating-circle').mouseenter(function() {
$(this).prevAll().addBack().addClass('rating-hover');
});

$('.rating-circle').mouseleave(function() {
$(this).prevAll().addBack().removeClass('rating-hover');
});

$('.rating-circle').click(function() {
$(this).prevAll().addBack().addClass('rating-chosen');
});

$('#rating-container').mouseenter(function() {
$(this).children().removeClass('rating-chosen');
});
});

</script>
</body>
</html>

Kld Kld
Answer

By deault your browser is looking for a relative link to the html file

file://ajax.aspnetcdn.com/ajax/jQuery/jquery-2.1.4.min.js 

You need to make it absolute

<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-2.1.4.min.js"></script>
Comments