Pure JavaScript Star Rating Example

Today, We want to share with you Pure JavaScript Star Rating Example.In this post we will show you how to display rating stars in javascript, hear for Best Free star rating In JavaScript & CSS we will give you demo and example for implement.In this post, we will learn about A simple star rating system using vanilla JS, CSS and HTML with an example.

Pure JavaScript Star Rating Example

There are the Following The simple About Pure JavaScript Star Rating Example Full Information With Example and source code.

As I will cover this Post with live Working example to develop 5 star rating javascript, so the A Simple JavaScript Technique for Filling Star Ratings for this example is following below.

Also Read This πŸ‘‰   Rating Stars with simple jQuery

5 star rating in javascript source code

index.html

<!DOCTYPE html>
<html>
<head>
<title>Pure JavaScript Star Rating Library – JavaScript-Rating</title>
<style type="text/css">
.star-rated {
  float: left;
  unicode-bidi: bidi-override;
  direction: rtl;
  font-size: 28px;
  margin-top: -11px;
  color: #c60000;
  margin-left: 10px;
  margin-right: 10px;
}
.star-rated > span {
  display: inline-block;
  position: relative;
  width: 0.7em;
  cursor: pointer;
}
.star-rated > span:hover:before,
.star-rated > span:hover ~ span:before,
.star-rated > span.upstar-rated:before,
.star-rated > span.upstar-rated ~ span:before {
  content: "\2605";
  position: absolute;
}
</style>
</head>
<body>

<p></p>

<div id="Appstar-rated" class="star-rated">
  <span id="spanstar-ratedFirst" title="5">β˜†</span>
  <span id="spanstar-ratedsecond" title="4">β˜†</span>
  <span id="spanstar-ratedthird" title="3">β˜†</span>
  <span id="spanstar-ratedFourth" title="2">β˜†</span>
  <span id="spanstar-ratedFifth" title="1">β˜†</span>
</div>
<script>
document.getElementById('Appstar-rated').addEventListener('click', function(event) {
  if (event.target.tagName.toLowerCase() != 'span') return;
  
  if (event.target.classList.contains('upstar-rated')) {
    event.target.classList.remove('upstar-rated');
  } else {
    Array.prototype.forEach.call(document.getElementsByClassName('upstar-rated'), function(el) {
      el.classList.remove('upstar-rated');
    });
    event.target.classList.add('upstar-rated');
  }
});
</script>
</body>
</html>

Web Programming Tutorials Example with Demo

Read :

Also Read This πŸ‘‰   Star Rating System using jQuery

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

Free Live Chat for Any Issue

I hope you get an idea about Pure JavaScript Star Rating Example.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

3.6/5 - (63 votes)