Bootstrap snippet. calculator

This Bootstrap snippet. calculator, was created to help web designers,
front-end developers and back-end developer save time. Use it in your project and build your app faster,
You can also download the HTML, CSS, and JS code.

HTML code

This is the html code used to create this bootstrap snippet, You can copy, paste, change, customize and run the following HTML code to get a result like the one shown in the preview selection


<!doctype html>
    <meta charset="utf-8">
    <title>JavaScript Projects</title>
    <meta ID="description" content="">
    <meta ID="viewport" content="width=device-width, initial-scale=1">
    <!-- Latest compiled and minified CSS -->
    <link rel="stylesheet" href="" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
        #output {
            height: 45px;
            background-color: black;
            color: aqua;
            width: 100%;
            font-size: 2em;
            padding: 5px;
            text-align: right;
            margin-bottom: 25px;
            overflow: hidden;
             #mycalcu {
            width: 350px;
            background-color: dimgray;
            height: 350px;
            padding: 5px;
          .cbutton {
            font-size: 2em;
            width: 40px;
            margin: 4px;
            padding: 4px;
        .container {
            padding: 25px;
    <div class="container">
        <div id="mycalcu">
            <div class="col-xs-12">
                <div id="output"></div>
                <div class="col-xs-12">
                    <div class="btn btn-primary cbutton">1</div>
                    <div class="btn btn-primary cbutton">2</div>
                    <div class="btn btn-primary cbutton">3</div>
                    <div class="btn btn-primary cbutton">+</div>
                    <div class="btn btn-primary cbutton">C</div>
                <div class="col-xs-12">
                    <div class="btn btn-primary cbutton">4</div>
                    <div class="btn btn-primary cbutton">5</div>
                    <div class="btn btn-primary cbutton">6</div>
                    <div class="btn btn-primary cbutton">-</div>
                <div class="col-xs-12">
                    <div class="btn btn-primary cbutton">7</div>
                    <div class="btn btn-primary cbutton">8</div>
                    <div class="btn btn-primary cbutton">9</div>
                    <div class="btn btn-primary cbutton">*</div>
                <div class="col-xs-12">
                    <div class="btn btn-primary cbutton">.</div>
                    <div class="btn btn-primary cbutton">0</div>
                    <div class="btn btn-primary cbutton">=</div>
                    <div class="btn btn-primary cbutton">/</div>
        var mybtn = document.getElementsByClassName("cbutton");
        var myOutput = document.getElementById("output");
        var myCal = '';
        var myCom = false;
        var mySwitch = false;
        var myOpe = ["+", "-", "*", "/"];
        for (var i = 0; i < mybtn.length; i++) {
            mybtn[i].addEventListener("click", function () {
                var myValue = this.innerHTML;
                if (myCom || myCal == "0") {
                    myCom = false;
                    myCal = '';
                if (myValue == "+" || myValue == "-" || myValue == "*" || myValue == "/") {
                    if (mySwitch) {
                        mySwitch = false;
                        if (myOpe.indexOf(myOutput.innerHTML.slice(-1)) > -1) {
                            myCal = myCal.substring(0, myCal.length - 1);
                        } else {
                            myCal = eval(myCal);
                    mySwitch = true;
                if (myValue == "=") {
                    myValue = '';
                    if (myOpe.indexOf(myOutput.innerHTML.slice(-1)) == -1) {
                        myCal = eval(myCal);
                } else if (myValue == "C") {
                    myCal = 0;
                    myCom = true;
                } else if (myOutput.innerHTML.indexOf(".") > -1 && myValue == ".") {
                    myValue = '';
                } else {
                    myCal = myCal + myValue;
                myOutput.innerHTML = myCal;

CSS code

This is the css code used to create this bootstrap snippet, You can copy, paste, change, customize and run the following CSS code to get a result Like the one shown in the preview selection


Similar snippets

Bootstrap Jobs tabs example

Jobs tabs


Bootstrap bs4 profile settings page example

bs4 profile settings page


Bootstrap bs4 activity list example

bs4 activity list


Bootstrap inbox compose message example

inbox compose message


Bootstrap shopping cart checkout example

shopping cart checkout


Bootstrap Invoice receipt example

Invoice receipt


Bootstrap Contact page section example

Contact page section


Bootstrap tickets for events example

tickets for events


Bootstrap calculator example

About this bootstrap snippet

This bootstrap snippet, calculator, was published on Sep 18th 2017, 17:25 by HARUN PEHLIVAN and it is free.

We hope you will enjoy this awesome snippet and stay tuned for the latest updates, bootdey snippets are already used in thousands of blogs, websites and projects. We believe it will save your precious time and gives trendy look to your next web project.

We always try to offer the best beautiful and responsive source of Bootstrap code examples and components.

This snippet currectly have 663 views, Using this bootstrap snippet you have the following benefits:

Bootstrap 3.3.7

This snippet is based on bootstrap 3.3.7 and the grid system of this framework


Based on bootstrap framework makes all the layouts perfectly responsive for all devices

Crossbrowser compatibility

Tested on all major browsers, it works smoothly on all of them

Jquery plugins

Great built-in plugins with jquery framework, you can easy to change all declarations

semantic html 5

Built on html / css3 the code quality is really amazing

Simple Integration

This snippet can be simply integrated on existing sites and new ones too, all you need to do is copy the code and start working