Showing posts with label html. Show all posts
Showing posts with label html. Show all posts

Decode HTML Entities using Javascript

Tags: February 23, 2014 1:13 PM
0 comments

I came into situation where I need to pass some string to Pen Editor instance. The problem is the string is already encoded to HTML entities by PHP's htmlentities(). So, when I have value like This is <strong>strong</strong> element. The Pen editor instance convert it into:

This is <strong>strong</strong> element

Instead of this:

This is strong element

The Solution

The solution is pretty dead simple just inject the string into textarea element and call the value property to get the content instead of innerHTML.

function decodeHtml(html){
  var txt = document.createElement("textarea");
  txt.innerHTML = html;
  return txt.value;
}
If your string already came from textarea like in my case then you don't event need to create a single function.

References

Share on Facebook Twitter

How to Make Text Align Bottom using CSS

Tags: February 21, 2014 5:44 PM
0 comments

What I want to achieve is like picture below.

 

Getting The Job Done

The simple trick to make it works like expected is we need to treat the element as table element. Set display element to table-cell which has vertical-align, the property which what we want to align the text to the bottom. The example below makes H2 element align to the bottom.
h2.bottom {
   display: table-cell;
   vertical-align: bottom;
   height: 60px; /* it's better to make it static */
   line-height: 30px; 
   width: 400px;  /* only as example */
}

Share on Facebook Twitter