Showing posts with label HTML5 PLACEHOLDER. Show all posts
Showing posts with label HTML5 PLACEHOLDER. Show all posts

Tuesday, July 19, 2016

9 USEFUL TIPS AND TRICKS FOR WEB DEVELOPERS

INTRODUCTION

Alright guys, it has been a while since I shared with you all about some web development tips and tricks. If you were able to take classes in web design you would be fortunate enough to have had peers in the classroom to absorb knowledge from, and I want to bring that experience here. This time, I have a few useful tips and tricks up my sleeve. In this post, I have 9 useful HTML, CSS and Javascript Tips and Tricks I got it online and have been using them many times. A few of them are CSS3 and HTML5, so If you are a frontend developer like me, you will certainly find them useful.

1. USE THE HTML5 PLACEHOLDER

A useful script created to toggle between placeholder and normal javascript in field label. I know it's a bit redundant but if you want a more stable and clean solution for modern browsers, you can use the html5 placeholder now. I got this script from Franck Maurin.
Support: Opera 11+, Firefox 9+, Safari 5+, IE 10+
// jQuery code
var i = document.createElement("input");

// Only bind if placeholder isn't natively supported by the browser
if (!("placeholder" in i)) {
    $("input[placeholder]").each(function () {
        var self = $(this);
        self.val(self.attr("placeholder")).bind({
            focus: function () {
                if (self.val() === self.attr("placeholder")) {
                    self.val("");
                }
            },
            blur: function () {
                var label = self.attr("placeholder");
                if (label && self.val() === "") {
                    self.val(label);
                }
            }
        });
    });
}

<!-- html5 -->
<input type="text" name="search" placeholder="Search" value="">