Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="container"><div class="row">
  <div class="col-sm-12">
    <h1>Palindrome check</h1>
    <table class="table table-striped">
      <thead>
        <tr>
          <th>string</th>
          <th>palindrome?</th>
        </tr>
      </thead>
      <tbody>
        <tr><td class="string">123 456 789 09 87 65 43 21</td><td><span class="glyphicon"></span></td></tr>
        <tr><td class="string">012 34 3 21</td><td><span class="glyphicon"></span></td></tr>
        <tr><td class="string">put it up</td><td><span class="glyphicon"></span></td></tr>
        <tr><td class="string">stack cats</td><td><span class="glyphicon"></span></td></tr>
        <tr><td class="string">No ‘x’ in Nixon</td><td><span class="glyphicon"></span></td></tr>
        <tr><td class="string">step on no pets</td><td><span class="glyphicon"></span></td></tr>
        <tr><td class="string">Was it a car or a cat I saw?</td><td><span class="glyphicon"></span></td></tr>
        <tr><td class="string">A man, a plan, a canal - Panama!</td><td><span class="glyphicon"></span></td></tr>
        <tr><td class="string">Doc, note: I dissent. A fast never prevents a fatness. I diet on cod.</td><td><span class="glyphicon"></span></td></tr>
        <tr><td class="string">This is not a palindrome. That's the reason there's a red "x" instead of a green checkmark.</td><td><span class="glyphicon"></span></td></tr>
        <tr><td class="string">T. Eliot, top bard, notes putrid tang emanating, is sad; I'd assign it a name: gnat dirt upset on drab pot toilet.</td><td><span class="glyphicon"></span></td></tr>
      </tbody>
    </table>
  </div>
</div>
  
              
            
!

CSS

              
                
              
            
!

JS

              
                $(document).ready(function() {
  $("tbody tr").each(function() {
    var classes = isPalindrome($(this).children("td.string").text()) ? "glyphicon-ok text-success" : "glyphicon-remove text-danger";

    $(this).find("td .glyphicon").addClass(classes);
  });
});

function isPalindrome(str) {
    str = str.toLowerCase().replace(/[^a-z0-9]*/g, "");
    var halfLen = Math.floor(str.length / 2);
    var strHalf = str.substring(0, halfLen);
    var strHalfRev = str.substring(str.length-halfLen, str.length);

    return reverse(strHalfRev) == strHalf;
}

function reverse(s) {
  return s.split('').reverse().join('');
}
              
            
!
999px

Console