Created
March 19, 2013 16:55
-
-
Save srobbin/5197871 to your computer and use it in GitHub Desktop.
jQuery Plugin Workshop
Box Color
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h2>Colors</h2> | |
<ul> | |
<li>1</li> | |
<li>2</li> | |
<li data-color="blue">3</li> | |
<li>4</li> | |
<li>5</li> | |
</ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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