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

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

Quick-add: + add another resource

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

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="button button--1">1</div>
<div class="button button--2">2</div>
<div class="button button--3">3</div>
<div class="button button--4">4</div>
<div class="button button--5">5</div>
<div class="button button--6">6</div>
            
          
!
            
              .button
	background-color: blue
	width: 100px
	height: 100px
	float: left

	&--2
		background-color: red
	
	&--3
		background-color: green
	&--4
		background-color: yellow

	&--5
		background-color: blue
	
	&--6
		background-color: red
            
          
!
            
              //参考 https://app.codegrid.net/entry/practical-jquery-1
//    http://www.jquerystudy.info/reference/events/currentTarget.html
//関数を呼び出すときは()無しで
$('.button--1').on('click', doAlert);

function doAlert (){
	alert("button");
}

//無名関数を記述し、それを実行
$('.button--2').on('click', function(){
	alert("無名関数");
});

//複数のイベントをスペースでつなぐことが出来る
$('.button--3').on('click mouseenter', function(){
	alert("green");
});

//$('セレクタ').on({'key1':value1, 'key2':value2, 'key3':value2 });
//連想配列=オブジェクトの表記

$('.button--4').on({
	'click' : function(){
		alert("click");
	},
	'mouseenter' : function(){
		alert("enter");
	}
});

//関数名を指定して、複数イベントを登録する
$('.button--5').on({
	'click' : doClick,
	'mouseenter' : doMouseEnter
});

function doMouseEnter(){
	alert("mouse enter");
}

function doClick(){
	alert("doCLick");
}

//イベントオブジェクトを、実行する関数に渡すことが出来る
//二番目の引数に、{key: 値}を与えると、関数が受け取ったevent.dataの下に入る。
//のでこの例で言えば、event.data.valueに3が入っている。
$('.button--6').on('click', {value: 3,test: 4 },doCount);

//eはjQueryオブジェクトだが、e.currentTargetは単なる文字列のようなので、
//それに対してjQueryファンクションを実行する場合には、$()でまずラップする必要がある
function doCount (e){
	console.log(e);
	alert("count: " + e.data.value);
	alert("test: " + e.data.test);
	let htmlContent = $(e.currentTarget).html();
	console.log(htmlContent);
}
            
          
!
999px
Loading ..................

Console