How to convert a sting to title case with JavaScript

"hello world" => "Hello World"

We can convert a string to title case with below JavaScript function

String.prototype.toTitleCase = function()
{
    return this.replace(/\w*/g, function(str){return str.charAt(0).toUpperCase() + str.substr(1).toLowerCase();});
}
"hello world".toTitleCase(); // Output : Hello World

To capitalize only first letter with JavaScript check : How to capitalize first letter of a string with JavaScript

For who do not like prototype here is a Non prototype version for the same:-

function toTitleCase(string)
{
    return string.replace(/\w*/g, function(str){return str.charAt(0).toUpperCase() + str.substr(1).toLowerCase();});
}
   toTitleCase("hello world"); // Output : Hello World

Extra : Looking for angular solution read here : Angular TitleCase

How to remove attribute from HTML element using jQuery

$("p").removeAttr("style");

// remove style attribute from all <p> tags 

We can remove a attribute from HTML element with the help of jQuery removeAttr() function

The below example will show us how to remove attribute from HTML element using jQuery. In this example when you click the Remove button it will remove the href attribute from the link using the jQuery removeAttr() method.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Remove HTML Element Attribute using jQuery</title>
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
</head>
<body>

    <a href="#">Demo Link</a>
    <button type="button" class="remove-attr">Remove</button>

</body>
<script type="text/javascript">
    $(document).ready(function() {
        $(".remove-attr").click(function(){            
            $("a").removeAttr("href");
        });
    });
</script> 
</html>