cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv


A Pen By Captain Anonymous

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation


Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

              <div class="outer"></div>

	<li><a href="#" onclick="level(1)">Level One</a></li>
	<li><a href="#" onclick="level(2)">Level Two</a></li>
	<li><a href="#" onclick="level(3)">Level Three</a></li>
	<li><a href="#" onclick="level(4)">Level Four</a></li>

<a href="http://joseph.mx/blog/2015/06/21/Nth-Size-Sierpinski-Carpet-in-JQuery.html">Read the blog post about this here</a>

<p>You can go to higher levels by using the function "level" in the JavaScript Console (eg, "level(7)" will build the 7th level of the Sierpinski Carpet).</p>

              		.outer {
		  background: black;
		  width: 300px;
		  height: 300px;
		  display: block;

		.square {
		  background: white;
		  display: block;
		  float: left;
              function levelOne(){
	  for (i = 1; i <= 9; i++) {
	    $(".outer").append("<div class='square level1 square"+i+"'></div>");  
	  var width = $(".outer").width();
	  $(".square").css({"width":width/3, "height":width/3});
	  $(".square5").css({"background":"black", "border":"none"});

	function level(level){

		if(level == 1){
		} else {
			for(i = 2; i <= level; i++) {
			  var previous = i-1;

			  for (j = 1; j <= 9; j++) {
			  	if(j % 5 == 0){
			        $("<div class='square square"+j+" level"+i+"' style='background: black;'></div>").appendTo(".level" + previous)
			  	} else {
			        $("<div class='square square"+j+" level"+i+"'></div>").appendTo(".level" + previous)

			  var width = $(".level" + previous).first().width(); 
			  $(".level" + i).css({"width":width/3, "height":width/3});

			  $(".square5 *").css({"background":"black", "border":"none"});
Loading ..................