Skip to content

Instantly share code, notes, and snippets.

@srobbin
Created March 19, 2013 16:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save srobbin/5197871 to your computer and use it in GitHub Desktop.
Save srobbin/5197871 to your computer and use it in GitHub Desktop.
jQuery Plugin Workshop Box Color
<h2>Colors</h2>
<ul>
<li>1</li>
<li>2</li>
<li data-color="blue">3</li>
<li>4</li>
<li>5</li>
</ul>
// Clear the console
console.clear();
(function ($) {
$.fn.boxColor = function () {
return this.each(function () {
$(this).css("background", $(this).data("color") || "red");
});
};
$.expr[":"].boxcolor = function (element) {
return $(element).data("color");
};
})(jQuery);
$("li").boxColor();
$("li:boxcolor").css("border", "5px solid blue");
@import "compass";
body { padding: 10px; }
ul {
list-style: none;
margin: 0;
li {
float: left;
width: 50px;
height: 50px;
margin-right: 10px;
text-align: center;
border: 1px solid #ccc;
line-height: 50px;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment